Wednesday, June 25, 2014

Play 2.2.x and Akka Logging

It gets frustrating if logs go missing when we are struggling to debug something. Something like this is very likely to happen when we use a third party library which uses Akka internally within our Play application.

After struggling for quite sometime, I figured out the changes that were needed to configure the log settings correctly. Some of the things are specified in loggingSetting configuration for Play 2.3 but I wasn't looking at it cos I was using an older version of Play(2.2.x).

It is very simple and requires only 2 small changes - one in conf/application.conf and the other in logger.xml. Update the log level for play actors as well as the actors in the third party library,

  play.akka.loglevel="DEBUG"
  third-party-lib{
   akka {
    loggers = ["akka.event.slf4j.Slf4jLogger"]
    loglevel = "DEBUG"
   }
  }

And now, add specific loggers in conf/logger.xml.

  <logger name="play" level="DEBUG"/>
  <logger name="application" level="DEBUG"/>
  <logger name="com.project.actors" level="DEBUG"/>
  <logger name="third.party.lib.actors" level="DEBUG"/>

Note: The "name" attribute should be set to the required package name.

A sample configuration file which adds the logs to just the file logs/application.log