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?


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

链接地址: http://www.djcxy.com/p/95132.html

上一篇: Playframework运行和Global.onStart

下一篇: 将日志记录级别设置为在Playframework 2.0生产中进行调试?