I use SLF4J
with Logback
in my desktop application.
Application can find configuration file (target/classes/logback.xml
) and configure logger in a correct way. But when I change configuration file (<root level="debug">
) and restart application nothing changes in my logger settings.
Here is my configuration:
<configuration debug="true" scan="true" scanPeriod="10 seconds">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${consoleLayoutPattern}</pattern>
</encoder>
</appender>
<appender name="LOG_FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${fileName}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${filePattern}</fileNamePattern>
<maxHistory>60</maxHistory>
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${rollingFilePatternLayoutPattern}</pattern>
</encoder>
</appender>
<root level="error">
<appender-ref ref="LOG_FILE" />
<appender-ref ref="CONSOLE" />
</root>
</configuration>
What did I do wrong? Is there any solution to trace jar inner xml
configuration changes and refresh logging setting after application restart?
In order not to re-build your project you have in fact to put your log configuration file outside of your project. I mean put a path to this file in your application properties.
If you're using Spring Boot you can configure the path to the log config file in the application.properties
file like this :
logging.config=/home/path_to/logback.xml
Doing this when you will start your application it will use the one specified and you will not have to rebuild your project.
As this path can change depending on your environment, I strongly advise you for staging or production to externalize the log config file as previously demonstrated but also use external application.properties file.
You can simply do this when launching your java program:
java -Dspring.config.location=file:///home/.../application.properties
Good practices like this is further explained on the Twelve Factors website, configuration part is here.
Hope this helps