Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't my akka logging working inside of play

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.

like image 302
Blankman Avatar asked Sep 03 '25 08:09

Blankman


2 Answers

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" />
like image 144
sarveshseri Avatar answered Sep 04 '25 22:09

sarveshseri


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

like image 45
Vishal John Avatar answered Sep 04 '25 23:09

Vishal John