Reputation: 392
I am trying to edit my logging configuration file so that the levels for the logs would be different based on either it is in a development environment or production environment for example
in dev would be
<logger name="1" level="debug"/>
<logger name="2" level="debug"/>
<logger name="3" level="debug"/>
in production the loggers should be
<logger name="1" level="warn"/>
<logger name="2" level="warn"/>
<logger name="3" level="warn"/>
is there a way to do this with an environment variable and condition statement? I want to try to avoid having a log file specific to each environment
Upvotes: 0
Views: 999
Reputation: 10192
You just need to use two configuration files for logback, one that would log at least debug
level and the other that would log at least warning
.
Quote from here:
Logback tries to find a file called logback.groovy in the classpath.
If no such file is found, logback tries to find a file called logback-test.xml in the classpath.
If no such file is found, it checks for the file logback.xml in the classpath..
There is actually 4 and 5, but this is enough for the explanation.
So basically use logback-test.xml
for dev, and logback.xml
for prod. Of course, don't deploy logback-test.xml
to prod.
Upvotes: 1