Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set logging level to debug in Playframework 2.0 production?

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?

like image 919
schmmd Avatar asked Jun 08 '12 20:06

schmmd


People also ask

What is debug logging level?

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 .

How do you increase debug level?

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.


1 Answers

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

like image 167
kheraud Avatar answered Oct 21 '22 23:10

kheraud