Search code examples
scalaakka

My log messages are working for one file with akka typed, but not for classic actor


I'm not sure what is going on, but my logging is working for my akka typed actors but not for my classic actors.

Both belong to the same root package also, this is my setup:

 libraryDependencies ++= Seq(
      "io.netty" % "netty-all" % "4.1.68.Final",
      "com.typesafe.akka" %% "akka-actor" % AkkaVersion,
      "com.typesafe.akka" %% "akka-actor-typed" % AkkaVersion,
      "com.typesafe.akka" %% "akka-stream" % AkkaVersion,
      "ch.qos.logback" % "logback-classic" % "1.2.10",
      scalaTest % Test
    )

My logback.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
        <encoder>
            <pattern>[%date{ISO8601}] [%level] [%logger] [%marker] [%thread] - %msg MDC: {%mdc}%n</pattern>
        </encoder>
    </appender>

    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
        <file>target/myapp-dev.log</file>
        <encoder>
            <pattern>[%date{ISO8601}] [%level] [%logger] [%marker] [%thread] - %msg MDC: {%mdc}%n</pattern>
        </encoder>
    </appender>

    <logger name="myapp" level="ALL" />

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

In both files I have this in the imports:

package myapp.typed

import ch.qos.logback.classic.Logger
import org.slf4j.LoggerFactory

inside of the typed actors I have:

context.log.info("Type actors starting...startup message received..")




package myapp.classic

import ch.qos.logback.classic.Logger
import org.slf4j.LoggerFactory

Inside of the classic actors I have:

   ....  with ActorLogging {

   log.debug("hello...")

In my applications main I am doing this:

  implicit val system = akka.actor.ActorSystem("my-classic-actor-system")
  implicit val typedGuardian = system.spawn(MyTypedActor(), "akka-typed-root")

I'm not sure if that is relevant but maybe it is...(mixing typed actors with classic)

What could the issue be?


Solution

  • I would check log level in your config, or set it explicitly:

    akka {
      loglevel = "DEBUG"
      log-config-on-start = on  # if you want to debug config
    }
    

    Also check which logger is used:

    Akka (2.3.0) fails to load Slf4jEventHandler class with java.lang.ClassNotFoundException

    I also don't see logback dependency in your libs. Something like that would work:

    val AkkaVersion = "2.6.18"
    libraryDependencies ++= Seq(
      "com.typesafe.akka" %% "akka-slf4j" % AkkaVersion,
      "ch.qos.logback" % "logback-classic" % "1.2.9"
    )
    

    Finally, try to print higher errors like info or error to see if that's a log level issue.

    If nothing helps, you can debug the logging code itself and see how it's configured but I think that won't be necessary.