[Play-2.1.1] Make Akka aware of Play's logback configuration

1,363 views
Skip to first unread message

oblivion

unread,
Apr 16, 2013, 7:23:07 PM4/16/13
to play-fr...@googlegroups.com
How do I make Akka aware of Play's logback config (application-logger.xml)?

In my case it is completely ignored:
The log is ONLY printed to stdout. I expect it to be logged to the File-Appender defined in application-logger.xml

It does not make a difference if I rename application-logger.xml to logback.xml.

########## Actor-class:

  class Dispatcher extends Actor with ActorLogging {
    // prints to stdout ONLY:
    log.error("[akka-logger] dispatch started...")
  }

########## conf/application.conf:

 play {
   akka {

    #log-config-on-start = on
    loggers = ["akka.event.slf4j.Slf4jLogger"]
    event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]  
    loglevel = DEBUG

    # and so on...
  }

########### conf/application-logger.xml

  <configuration>
  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>${application.home}/logs/application.log</file>
    <encoder>
      <pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</ pattern>
    </encoder>
  </appender>
  <!-- Using akka.event.slf4j.EventHandler does NOT make a difference here: -->
  <logger name="akka.event.slf4j.Slf4jLogger" level="ERROR" additivity="false">
    <appender-ref ref="FILE"/>
  </logger>

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

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

  <root level="ERROR">
    <appender-ref ref="STDOUT"/>
    <appender-ref ref="FILE"/>
  </root>

</configuration>

Alvaro Carrasco

unread,
Apr 17, 2013, 10:49:18 AM4/17/13
to play-fr...@googlegroups.com
Play makes use of a few Akka actor systems, the one that you configured is the internal one used by play. To configure the other ones I believe you do it outside the "play" brackets, this worked for me to configure both:

# play internal akka
play.akka {
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
}
# regular akka
akka {
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
}

I have seen a page somewhere describing the actor systems that play uses (and makes available) but I can't find it at the moment. (where is it?)

Alvaro


2013/4/16 oblivion <recalc...@web.de>

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Message has been deleted

oblivion

unread,
Apr 17, 2013, 3:07:04 PM4/17/13
to play-fr...@googlegroups.com
Thanks Alvaro,

that works to some extent.
The final problem is that the akka logger (outside the play brackets) does not recognize the application-logger.xml so I have no control over the place where it logs its messages to (stdout, file, etc)

Copying the application-logger.xml file to logback.xml does not work either.

Also why are there 3 places to define log-levels:
application.conf
akka-config
application-logger.xml

oblivion

unread,
Apr 17, 2013, 5:28:28 PM4/17/13
to play-fr...@googlegroups.com
I found this stackoverflow-post which solves my issues:

mkr...@trialfire.com

unread,
Apr 28, 2014, 5:27:27 PM4/28/14
to play-fr...@googlegroups.com
I continue to be stumped by this. I can't for the life of me figure out how to get akka actors to log with logback. The moment I added my logging.xml the akka log output was deafeningly silent. I tried the following:


 <logger name="akka" level="DEBUG" /> in logger.xml


akka {
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  event-handlers = ["akka.event.slf4j.Slf4jLogger"]
  loglevel = "DEBUG"
}    ....in my application.conf

What am I missing? 

Yasuki Okumura

unread,
Apr 28, 2014, 8:28:28 PM4/28/14
to play-fr...@googlegroups.com
How about this:
<logger name="akka.event.slf4j.Slf4jLogger" level="DEBUG" additivity="false"> in logger.xml



--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mkr...@trialfire.com

unread,
Apr 28, 2014, 10:35:52 PM4/28/14
to play-fr...@googlegroups.com
Nope that didnt do it either. I'm still only getting ERROR level messages

mkr...@trialfire.com

unread,
Apr 28, 2014, 11:01:34 PM4/28/14
to play-fr...@googlegroups.com
So just to recap:

logger.xml now looks like this:

<configuration>
    
  <conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
  
  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
     <file>${application.home}/logs/applicationmax.log</file>
     <encoder>
       <pattern>%date ---- [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
     </encoder>
   </appender>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%coloredLevel %logger{15} - %message%n%xException{5}</pattern>
    </encoder>
  </appender>
  
  <logger name="play.akka" level="DEBUG" additivity="false">
   <appender-ref ref="FILE"/>
   </logger>
  
  <logger name="play" level="DEBUG" />
  <logger name="application" level="DEBUG" />
 
  <root level="DEBUG">
    <appender-ref ref="STDOUT" />
    <appender-ref ref="FILE" />
  </root>
  
</configuration>

application.conf looks like this:

akka {
  akka.loggers = [ "akka.event.slf4j.Slf4jLogger"]
  loglevel = DEBUG
}

and this is how I get my logger in my java UntypedActor

final LoggingAdapter logger = Logging.getLogger(getContext().system(), getClass().getName());

and this is how I use it

logger.error("This is error");
logger.debug("This is debug");
logger.warning("This is warning");
logger.info("This is info");

And this is what I see in STDOUT

[ERROR] [04/28/2014 22:54:22.384] [application-akka.actor.default-dispatcher-10] [actor.event.MeteringActor]This is error
[DEBUG] [04/28/2014 22:54:22.384] [application-akka.actor.default-dispatcher-10] [actor.event.MeteringActor] This is debug
[WARN] [04/28/2014 22:54:22.384] [application-akka.actor.default-dispatcher-10] [actor.event.MeteringActor] This is warning
[INFO] [04/28/2014 22:54:22.384] [application-akka.actor.default-dispatcher-10] [actor.event.MeteringActor] This is info



I Do not see any of the above in my log file, only play's log messages and any non-akka log messages. 

[Rant] 
This is why people shit all over play all the time. Lack of, or incorrect documentation and endless frustration trying to get simple stuff working. I mean LOGGING, how basic is that? - I feel like a complete idiot because I killed an entire day on this and it still doesn't work [End Rant]
 


Yasuki Okumura

unread,
Apr 28, 2014, 11:45:31 PM4/28/14
to play-fr...@googlegroups.com
Which version of akka are you using? I guess you are using v2.1.0 since
you are using play2.1.1. There is little bit difference between akka
logging v2.2 and v2.1.

So you should the following:
In Play2.1
akka {

 event-handlers = ["akka.event.slf4j.Slf4jEventHandler”]

 loglevel = “DEBUG”

}

<logger name="akka.event.slf4j.Slf4jEventHandler" level="DEBUG" additivity="false">
<appender-ref ref="FILE"/>
</logger> in logger.xml

In Play2.2
akka {

 loggers = ["akka.event.slf4j.Slf4jLogger”]

 loglevel = “DEBUG”

}

<logger name="akka.event.slf4j.Slf4jLogger" level="DEBUG" additivity="false">
<appender-ref ref="FILE"/>
</logger> in logger.xml

Actually I've never tried Play + Java with above configuration but this works for me with play2.2 + scala.

If you want more details, you should see these:
http://doc.akka.io/docs/akka/2.1.0/java/logging.html
http://doc.akka.io/docs/akka/2.2.0/java/logging.html

PS. I love play framework and I know play team work hard. If you feel lack of, or incorrect documentation, they are welcome your PR, I think. Actually I would like to do but English is not my first language so it is difficult for me..



mkr...@trialfire.com

unread,
Apr 29, 2014, 9:43:28 AM4/29/14
to play-fr...@googlegroups.com
Hi Yasuki,

   Thank you for the reply. Actually I'm using play with an upgraded version of Akka (2.2.3). I've tried this on play 2.2.1 and 2.2.2.

mkr...@trialfire.com

unread,
Apr 29, 2014, 11:21:00 AM4/29/14
to play-fr...@googlegroups.com
Ok I believe I've finally solved this mystery. The missing element was a line in the logger.xml

  <logger name="[PACKAGE NAME]" level="DEBUG" />

In my case all my akka actors are in a top level package called "actor" so by adding 

  <logger name="actor" level="DEBUG" />

If your actors in several packages then you'll want to add several lines as above.

This logger does nothing at all and I removed it from logger.xml
 <logger name="akka.event.slf4j.Slf4jLogger" level="DEBUG" additivity="false">
   <appender-ref ref="FILE"/>
 </logger>

Now lets discuss application.conf, mine has this 

akka {
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  loglevel = "DEBUG"   #This loglevel should match whats in logger.xml
}


The loglevel here works in conjunction with log level in you logger.xml. You can play with setting them differently and you should notice that this loglevel should be more specific then the one in logger.xml however the only sane setting is for them to match.

So in summary. I'm using play2.2.1 (also tested with play2.2.2), upgraded version of akka ( "com.typesafe.akka" %% "akka-actor" % "2.2.3" ) and the LoggingAdapter to log to slf4j in my Java actors 
 LoggingAdapter logger = Logging.getLogger(getContext().system(), this);

Hopefully this thread will save people hours (in my case days) of frustration when trying to setup consolidated akka, play, application logging.

-Max
 


Kip Sigman

unread,
May 6, 2014, 2:44:33 PM5/6/14
to play-fr...@googlegroups.com
Based on your findings (and some experimentation of my own), I added a section in the Play docs for logging config that should help people with this scenario: http://www.playframework.com/documentation/2.3-SNAPSHOT/SettingsLogger (see "Akka logging configuration" section at the bottom).

Ian Rae

unread,
May 7, 2014, 9:12:25 AM5/7/14
to play-fr...@googlegroups.com
Thanks Max and Kip! 


Ivan

unread,
Nov 26, 2015, 7:22:37 PM11/26/15
to play-framework
Is there already a solution for this? I'm using Play 2.4 and experiencing the same problem... And I can't use my package name because I don't have all my actors in a separate package. Thanks.

P.S. I followed the akka logger settings in the documentation https://www.playframework.com/documentation/2.4.x/SettingsLogger 
Reply all
Reply to author
Forward
0 new messages