Akka & SLF4J configuration

I've read the Akka Logging tutorial and I'm still a bit confused as to how to get Akka to work with SLF4J. I understand that the correct, general process is:

  • Include a module akka-slf4j

    in the execution path path that transitively pulls inslf4j-api

  • Include SLF4J backend in execution path like Logback
  • Set up a logging backend (somehow, see below)
  • Create and use SLF4J registrars as usual.

So first, if I missed or misunderstood any of the steps above, please start by fixing it! Assuming that I am more or less correct, I am still completely incomprehensible on two points:

  • Am I setting up Akka or setting up the SLf4J "backend"? (see below).
  • Why am I not running the SLF4J recorders as usual? (see below).

Configuration

If I would normally use SLF4J / Logback, I would just make sure there was a file in the runtime path logback.xml

. Or, if I used slf4j-simple

, I would make sure there was a file in the runtime path slf4j.properties

. But with Akka it seems that I need to declare the section akka.loggers

like this:

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

      

... and / or configure the SLF4J binding as usual. So what is it?

Registrar activation

I don’t understand why you don’t start SL4J recorders as usual. Usually, outside of the cast / cast system, my logger instance will look like this:

public class FizzBuzz {
    Logger logger = Logger.getLogger(FizzBuzz.class);

    // ...etc.
}

      

But in the Akka docs it seems that I should be creating them like this:

public class FizzBuzz {
    LoggingAdapter log = Logging.getLogger(system.eventStream(), "my.string");

    // ...etc.
}

      

Why?!?!

Also, bonus points if anyone can explain to me the use / purpose of "MDC values" (???) and DiagnosticLoggingAdapter

.

+3


source to share


1 answer


Akka uses actors for logging as well for non-blocking reasons. Every time you want to register something and use the logger that Akka provides (like the one available after adding an attribute ActorLogging

), it actually sends a message to the registrant and the actor takes care of interacting with the backend maintenance base of your choice ...



As for MDC

, it is usually used to filter and send data to different applications based on some value. MDC

stands for Mapped Diagnostic Context, which means you will have a context with some values ​​that you can use to distribute your logs in an intelligent and elegant way.

+3


source







All Articles