Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Akka SLF4J and logback in Scala

I am trying to set up some basic logging for my akka actor system, but so far am only getting the standard logs and none of my added logs or an output file. I have followed along with the akka docs for logging and have set up the following:

  • I added these dependencies to the build.sbt file

    "com.typesafe.akka" %% "akka-slf4j" % "2.3.14"
    "ch.qos.logback" % "logback-classic" % "1.0.9"
    
  • I added this to the application.conf file

    akka {
        loggers = ["akka.event.slf4j.Slf4jLogger"]
        loglevel = "DEBUG"
    }  
    
  • logback.xml is in src/main/resources

    <configuration>
        <appender name="FILE" class="ch.qos.logback.core.FileAppender">
            <File>./logs/akka.log</File>
            <encoder>
                <pattern>%d{HH:mm:ss.SSS} [%-5level] %msg%n</pattern>
            </encoder>
        </appender>
        <root level="info">
            <appender-ref ref="FILE" />
        </root>
    </configuration>
    
  • This is what I'm hopping is supposed to do the logging

    import akka.event.Logging
    
    val log = Logging(context.system, classOf[TickActor])
    log.info("Good Luck!")
    

I do not receive and messages of the failure from the standard logging, and I haven't been able to find additional solutions much different from what I already have. I have tried the suggestions in this question. It seemed to be the same issue I'm having, but the suggestions did not work. Have I missed a step or configured something wrong?

like image 540
the3rdNotch Avatar asked Jan 19 '16 20:01

the3rdNotch


People also ask

Does SLF4J use Logback?

Native implementation of slf4j is logback, thus using both as logger framework implies zero memory and computational overhead.

What is Akka logging?

Logging in Akka is not tied to a specific logging backend. By default log messages are printed to STDOUT, but you can plug-in a SLF4J logger or your own logger. Logging is performed asynchronously to ensure that logging has minimal performance impact.

What is Logback?

Logback is one of the most widely used logging frameworks in the Java Community. It's a replacement for its predecessor, Log4j. Logback offers a faster implementation, provides more options for configuration, and more flexibility in archiving old log files.

What is Akka typed?

Akka “Typed Actors”, now replaced by Akka Typed, were an implementation of the Active Objects pattern. Essentially turning method invocations into asynchronous dispatch instead of synchronous that has been the default way since Smalltalk came out.


1 Answers

Everything looks correct except for the missing akka.logging-filter setting. Here how it should look like:

akka {
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  loglevel = "DEBUG"
  logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
}

Here is a project with the same setup that has logging working: application.conf and logback.xml.

Explanation from the docs:

You need to enable the Slf4jLogger in the loggers element in the Configuration. Here you can also define the log level of the event bus. More fine grained log levels can be defined in the configuration of the SLF4J backend (e.g. logback.xml). You should also define akka.event.slf4j.Slf4jLoggingFilter in the logging-filter configuration property. It will filter the log events using the backend configuration (e.g. logback.xml) before they are published to the event bus.

and

Warning! If you set the loglevel to a higher level than "DEBUG", any DEBUG events will be filtered out already at the source and will never reach the logging backend, regardless of how the backend is configured.

which you took care of already.

like image 74
yǝsʞǝla Avatar answered Sep 17 '22 17:09

yǝsʞǝla