Currently I have logback configuration file i.e logback.xml
which is src/main/resources
. I want to set the logging level but i want control outside of
One way that it worked for us was to externalize the configuration file like below. Ignore the spring profiles part if that doesn't apply to you. So as soon as you update the configuration in logback-include.xml
, let's say by changing root level to info, the application picks it up within 30 seconds (configurable).
Reference: https://logback.qos.ch/manual/configuration.html#fileInclusion
web.xml
We used spring profiles, but it works even without it.
spring.profiles.active
dev
ch.qos.logback.ext.spring.web.LogbackConfigListener
logbackConfigLocation
classpath:properties/${spring.profiles.active}/logback.xml
logback.xml (in the classpath)
Note the debug="true"
which will tell you when the configuration is updated.
logback-include.xml (external location)
Note the use of
instead of configuration. Don't miss this part!
${logfile-path}/log-file.log
logFile.%d{yyyy-MM-dd}.log
7
%date [%thread] %-5level %logger{35} - %msg%n