Make Akka aware of Play's logback configuration

岁酱吖の 提交于 2019-12-04 04:26:55

I had the same problem. I'm using play 2.2.1 (also tested with 2.2.2) and upgraded version of akka 2.2.3 (But it also works with the version that comes with play). I should also note that I'm using Java not Scala. Here is what I did.

application.conf:

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

And in my logger.xml 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] --  %X{akkaSource} -- 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" level="DEBUG" />
  <logger name="application" level="DEBUG" />
    <!-- use the package names of classes for specific loggers  -->
  <logger name="actor" level="DEBUG" />

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

</configuration>

The key thing to note is that I use the root package name where the actors are as my logger. You can be as specific as you like ie com.actors or com.actors.someactors etc...

You can see more on this google group thread in the play-framework group:

Make Akka aware of Play's logback configuration

The default file name used by play for logback is logger.xml - see reference. You may also want to change the root level from error to debug to make sure you get any log messages at all at root level.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!