How to log Filename and Linenumber in Akka Classic Actor?

96 views Asked by At

We use logback as the logging backend for Akka as described here: https://doc.akka.io/docs/akka/current/logging.html

But if I use this logback snippet

<pattern>%d{HH:mm:ss.SSS} %-5level [%thread] [%logger] [%F:%L] [%mdc{akkaSource:-}] %msg [%mdc]%n</pattern>

I see ... [Slf4jLogger.scala:83] ... as file name and line number, which seems to be a class from the akka library.

How do I get the real location of the logging statement?

1

There are 1 answers

0
Chris W. On BEST ANSWER

Patrik Nordwall answered this here: https://discuss.lightbend.com/t/akka-actor-logging-of-line-numbers/7345

"Akka’s internal logging is asynchronous, meaning that log messages emitted via the akka.event.LoggingAdapter is sent to the actor Slf4jLogger. It’s the Slf4jLogger actor that will call the slf4j.Logger method and therefore the thread and source line number is from the Slf4jLogger actor.

That is by design and there is no work around for that for Akka’s internal logging.

For your own logging you don’t have to use Akka’s LoggingAdapter. You can log directly to your own slf4j.Logger.

More info at https://doc.akka.io/docs/akka/current/logging.html#slf4j"