Why isn't my akka logging working inside of pl

2019-07-05 08:07发布

My logging is working fine from within my play code, but the akka code I have isn't logging to file/stdout.

class EmailActor extends Actor with ActorLogging {
  import EmailActor._

  log.info("email actor hatched..")
...
}

When I create this actor I don't see the logging entries in either the log file or stdout.

I have the default application.conf from this activator template: https://github.com/playframework/play-scala/blob/master/conf/logback.xml

Do I need to modify my logback file with some akka label?

Update

I have done this now in my application.conf:

akka {
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  #loggers = ["akka.event.Logging$DefaultLogger"]

  loglevel = "DEBUG"
  logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"

  actor {
    debug {
      lifecycle = on
    }
  }
}

In my dependencies I have added this (and are both added to my play app's dep):

val akkaSlf4j = "com.typesafe.akka" %% "akka-slf4j" % Version.akkaSlf4j
val logback = "ch.qos.logback" % "logback-classic" % Version.logback

My logback.xml looks like:

<!-- https://www.playframework.com/documentation/latest/SettingsLogger -->
<configuration>

  <conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel" />

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>${application.home:-.}/logs/application.log</file>
    <encoder>
      <pattern>%date [%level] from %logger in %thread - %message%n%xException</pattern>
    </encoder>
  </appender>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%coloredLevel %logger{15} - %message%n%xException{10}</pattern>
    </encoder>
  </appender>

  <appender name="ASYNCFILE" class="ch.qos.logback.classic.AsyncAppender">
    <appender-ref ref="FILE" />
  </appender>

  <appender name="ASYNCSTDOUT" class="ch.qos.logback.classic.AsyncAppender">
    <appender-ref ref="STDOUT" />
  </appender>

  <logger name="play" level="INFO" />
  <logger name="application" level="DEBUG" />

  <!-- Off these ones as they are annoying, and anyway we manage configuration ourselves -->
  <logger name="com.avaje.ebean.config.PropertyMapLoader" level="OFF" />
  <logger name="com.avaje.ebeaninternal.server.core.XmlConfigLoader" level="OFF" />
  <logger name="com.avaje.ebeaninternal.server.lib.BackgroundThread" level="OFF" />
  <logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" />

  <root level="WARN">
    <appender-ref ref="ASYNCFILE" />
    <appender-ref ref="ASYNCSTDOUT" />
  </root>

</configuration>

I do not see any akka related logs in STDOUT or in my log files that I create using the ActorLogging log method.

3条回答
啃猪蹄的小仙女
2楼-- · 2019-07-05 08:09

Please put the following configuration in the application.conf

akka {
  loglevel = "DEBUG"

  actor {
    debug {
      lifecycle = on
    }
  }
}

You should be able to see the akka logs on STDOUT. Here's the link to akka logging page.

------------------ Update for SLF4J -----------------------

To use SLF4J logging, please refer to this answer

Add these two dependencies

"com.typesafe.akka" %% "akka-slf4j" % "2.2.3"
"ch.qos.logback" % "logback-classic" % "1.0.9"

Add this in config

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

With the above two changes, the logs should start appearing the file specified in logback.xml

查看更多
劫难
3楼-- · 2019-07-05 08:17

Notice how your logback.xml has this line,

<logger name="play" level="INFO" />

which allows a logger with loger_name equal to "play" to log at INFO level.

Similarly, you will need to add the following to your logback.xml,

<logger name="akka.event.slf4j.Slf4jLogger" level="DEBUG" />
查看更多
\"骚年 ilove
4楼-- · 2019-07-05 08:20

Is might just be that the default log level is set to WARN

Try changing <root level="WARN"> to <root level="DEBUG">

Or add a <logger level="DEBUG" name="..."> matching the EmailActor

查看更多
登录 后发表回答