in my conf/application.conf
I set my application's logging level to DEBUG
.
logger.application=DEBUG
This works fine when I sbt run
my application. However, when I run it in production mode with sbt start
, the log level gets overriden to INFO
.
Is there a way I can force play to use DEBUG
as my log level when running in production?
A debug level is a set of log levels for debug log categories, such as Database , Workflow , and Validation . A trace flag includes a debug level, a start time, an end time, and a log type. The log types are DEVELOPER_LOG , USER_DEBUG , and CLASS_TRACING .
You can change the logging level or trace level (also called the debug level) of a running process by sending a USR1 or USR2 signal to the process. Sending a USR1 signal changes the logging level and sending a USR2 signal changes the trace level.
You have two different loggers : play
logger and application
logger.
Here is an example of logger.xml for development mode :
<configuration>
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%coloredLevel %logger{15} - %message%n%xException{5}</pattern>
</encoder>
</appender>
<logger name="play" level="INFO" />
<logger name="application" level="DEBUG" />
<root level="ERROR">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Here the play logger is set for log level > INFO and your application logger (the one you use when doing Logger.debug/warn/error
) is set for log level > DEBUG. The root level is the default level for all the loggers but as each logger defines its own level, it is not needed.
You can create a prod-logger.xml file and launch your application in prod mode using : start -Dlogger.resource=conf/prod-logger.xml
.
Here is the configuration I use for a production server with two appenders to store level > DEBUG in a file and level > WARN in another file. There is also a TimeBasedRollingPolicy to have file rolling every day.
<configuration>
<appender name="FILE_DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${application.home}/logs/debug_log.log</file>
<encoder>
<pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${application.home}/logs/debug_log.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
<appender name="FILE_WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${application.home}/logs/warn_log.log</file>
<encoder>
<pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>WARN</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${application.home}/logs/warn_log.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>60</maxHistory>
</rollingPolicy>
</appender>
<logger name="play" level="INFO"/>
<logger name="application" level="INFO" />
<root level="WARN">
<appender-ref ref="FILE_DEBUG"/>
<appender-ref ref="FILE_WARN"/>
</root>
</configuration>
For more detail on configuration of logging have a look at Logback
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With