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!