Custom akka logger adapter

Hi there!
I have akka application that needs custom logging formatting. I use slf4j over logback:
There is ActorLogging trait mixed in actor and to log something I usually have to write log.debug("my object is {}", MyAwesomeFormatter.format(anyObject)).
The case is that I have to call MyAwesomeFormatter.format() whenever I use log.
What I want is to write some log adapter that will call MyAwesomeFormatter.format() under the hood:

def debug(t: String, arg: Any*): Unit = { if (isDebugEnabled) format(t, arg.map(MyAwesomeFormatter.format(_)): _*) }

Ideally I should select this new logger by configuration, e.g.

akka {
  loggers = ["com.my.AwesomeFormatterLogger"]
}

I know that I can override LoggingAdapter trait and then create new trait from ActorLogging ( which would return my new LoggingAdapter ), but this will not allow to use logger in configuration, rather as mixin with newly created trait instead of former ActorLogging.

Another way I look at is to write custom org.slf4j.Logger implementations but this doesn’t looks as easy deal.

Some ideas how can I achieve this?
Thanks in advance!

I don’t think that is easily doable in current Akka, for Akka Typed in 2.6 we are however working on trying to use SLF4J directly which should make it easier #26537

One thing you can do, is to create the SLF4J logger yourself and bypass the Akka logging infra, that’s only for your own logging though and not the internal actor system logging. Note that you should make sure to use an async appender if you do, so that each log write doesn’t block the actor on filesystem write etc. There is a bit of info about this in the docs: https://doc.akka.io/docs/akka/current/logging.html#using-the-slf4j-api-directly

@johanandren We decided to use overridden LoggingAdapter and not to touch akka.logger configuration. This is straightforward but clear way. Thanks for suggestions anyway!