0

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

Teddy Dong
  • 362
  • 1
  • 6
  • 20
  • Normally you have different files for each environment, and either you rename it in your build+deployment script, or you select it at startup, as here http://stackoverflow.com/questions/3120446/logging-for-application-in-different-environment-log4j – leonbloy Jun 03 '16 at 18:53
  • so there is no way to do an if statement stating if the environment is whatever? – Teddy Dong Jun 03 '16 at 19:24

1 Answers1

1

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:

  1. Logback tries to find a file called logback.groovy in the classpath.

  2. If no such file is found, logback tries to find a file called logback-test.xml in the classpath.

  3. 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.

cantSleepNow
  • 9,691
  • 5
  • 31
  • 42