Answer the question
In order to leave comments, you need to log in
Spring-Logback-Maven - how to move Logback settings to Spring application.properties?
Good afternoon!
Please help with Spring-Logback-Maven. I've already broken my head (((
So, Spring, Logback and Maven are used. I want to collect all the settings in Spring's application.properties, which will be outside the Jar collected by Maven.
I took out all the settings of interest from Logback.xml, now it's like this:
<configuration>
<property resource="application.properties" />
<timestamp key="byDate" datePattern="yyyyMMdd"/>
<!-- Send messages to System.out - CONSOLE -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
</encoder>
<withJansi>true</withJansi>
</appender>
<!-- Send messages to a file -->
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${logging.path}/${spring.application.name}-${byDate}.log</file>
<append>true</append>
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
</encoder>
</appender>
<root level="${logging.level}">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
#Spring settings
spring.application.name=MyApp
server.port=8087
# Logging settings
logging.level=INFO
logging.path=/Users/...some path.../logs/
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="file:application.properties"/>
</bean>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<excludes>
<exclude>path/to/application.properties</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy todir="target" overwrite="true">
<fileset dir="src/main/resources/">
<include name="*.properties"/>
</fileset>
</copy>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question