Thank you very much for taking the time and giving me feedback.
Visitors are also reading...
← PreviousNext →

Setting Logback with Play!Framework 2.0

11 Mar 2013

Last time I wrote about how to setup a Maven Project with SLF4J using Logback. In this post I will explain how to do the same for Play!Framework 2.0.

Steps to add Logback and SLF4J - DO NOT DO ANYTHING, it is already there

Well, the thing with Play!Framework is that you usually don’t need to do anything, as most of it is already there.
So it SLF4J and Logback.
There are a lot of troubleshooting.

Settings a logger.xml

In this post I will show how to set up Logback in Play!Framework 2.0 using a logger.xml file.
All Play has to say about it is in the application.conf file, a line specifying

# You can also configure logback (, by providing a logger.xml file in the conf directory .

To get things going, all you need to do is place a logger.xml file under conf folder. A basic logger.xml file looks like so (we will see soon that for Play!Framework this is not enough):


    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type
     ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->

            <!-- keep 1 days' worth of history -->

            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>

    <root level="info" additivity="false">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="FILE"/>



No log prints in windows

In Play!Framework 2.0.4, for some reason, windows did not get the log prints.
To resolve this you need to add an explicitly declare the logger.xml location like so :

play -Dlogger.file=conf/logger.xml run

Note that if you want to debug, you will have to write the following

play debug -Dlogger.file=conf/logger.xml run

important to place it before the -D flag.

Still no log prints - OR - Log level is incorrect

Looking in application.conf you will see the following properties


Or something of that sort..
Since you will configure your logger from logger.xml file, you need to switch these off.


And then redefine this in your logger.xml like so

<logger name="application" level="info" additivity="false">
    <appender-ref ref="STDOUT"/>
    <appender-ref ref="FILE"/>

<logger name="play" level="INFO" additivity="false">
    <appender-ref ref="STDOUT"/>
    <appender-ref ref="FILE"/>

Now, you should see the prints appear only once which is just as you would expect.

← PreviousNext →