2

I am using the Logback logging for my application, but I want certain logs to not be used based on the environment. For example, I have

<logger name="1" level="INFO" />
<logger name="2" level="INFO" />
<logger name="3" level="INFO" />
<logger name="4" level="WARN" />
<logger name="5" level="WARN" />
<logger name="6" level="WARN" />

I want to run all of the loggers on my dev environment, but disable the INFOS from logging when I am on my prod environment.

I am not sure how to do this, maybe with some conditional statement?

Teddy Dong
  • 362
  • 1
  • 6
  • 20

1 Answers1

1

Just like stated in the documentation:

You can provide a default logging configuration by providing a file conf/logback.xml (this is the default that Play is looking for).

But if you want custom logging for your dev environment or demo environment, you would create a conf/env/logback.demo.xml and when strting Play, you provide the correct logback.xml:

start -Dlogger.resource=conf/env/logback.demo.xml

adis
  • 5,901
  • 7
  • 51
  • 71
  • Is there a way to do it within one file and not have multiple custom ones? – Teddy Dong Jun 03 '16 at 16:50
  • I think it is possible, but I have never used it. Play has refactored out the direct dependency to Logback to be a Module. So with Dependency Injection you could use your own or even customise settings on application load, see https://www.playframework.com/documentation/2.5.x/SettingsLogger#using-a-custom-logging-framework – adis Jun 03 '16 at 19:56
  • so I used some conditional statements and matched on environment variables and was able to do it – Teddy Dong Jun 03 '16 at 20:45