3

The following resource states that Lagom uses an async logger in production. https://www.lagomframework.com/documentation/1.3.x/java/SettingsLogger.html

However, lagom also uses akka and akka advises that you use the akka-way of logging in your actors --> https://doc.akka.io/docs/akka/2.5/logging.html?language=java

The akka-way of logging (via a LoggingAdapter) basically forwards all log messages to a Logging actor. This is done to minimize the impact of Logging on your actor --> the logging is done asynchronously by another actor.

Am I correct that the combo of these leads to double async logging? Is this a problem? Is the async logging of slf4j to be preferred above the akka way of logging or the other way around? Arguments pro, arguments con?

1 Answers1

4

There are many places in Lagom that we need to log and where we are not inside an Actor. Also, with respect to user code. Most user code is written outside an Actor but is run inside an Actor.

It's true that there is an overhead when logging through ActorLogging, but that's preferable than user-defined blocking logger that happens to be called from inside an Actor.

Renato
  • 1,170
  • 1
  • 8
  • 11
  • Does that mean that it is perfectly valid to log in these places "outside" of an actor via slf4j directly. It is not that the LoggingAdapter available in the actor is passed on to the pojo's living "behind" the actor. It is better for these Pojo's to grab their own logger instead? Tnx for the clarification – Jo Vanthournout Jan 11 '18 at 06:24
  • Yes, as long as you are using the async appender, there is no issue. If I'm not mistaking, the `ActorLogging` and all the infrastructure that is in place to support async logging in Akka was initially something that Akka needed for its own logging. They can't force users to configure an async appender and they don't want to block IO on their code base that could potentially slow down your application. – Renato Jan 11 '18 at 08:28
  • Any idea if there are problems to be expected using the MDC when you use both akka LoggingAdapter and SLF4J api together in the same "request" – Jo Vanthournout Jan 11 '18 at 10:03