It is natural to use ActorLogging when you need to provide a logger instance inside your Actor. Yet from time to time you might see instead logging traits (ie. LazyLogging or StrictLogging) from scala-logging. Usually, that could be seen in the code where Actor Model meets Dataflow or Reactive Streams. Can we use those two solutions interchangeably? Let’s look into details.

ActorLogging is deeply integrated with Akka. By default, it provides a Mapped Diagnostic Context (see DiagnosticActorLogging) with a bunch of useful information, including a full path of the actor in the actor tree. Also, some of the logging settings are shared with Akka configuration, so if you change for instance akka.loglevel in your application.conf it will have an effect on logs reported by your actor. It is also important to note that log instance provided by ActorLogging is supposed to be used inside an actor, so do not propagate it to deferred computations (ie. Futures).

scala-logging is a more general solution. Having no connections to Akka, it cannot provide a proper context of the actor. Also, logging configuration is completely separated from Akka settings. There is no need to protect logger instance, so you can pass it whenever you need it.

To sum up, whenever logging occurs inside an Actor body - use ActorLogging to keep the context of the logging information. In all other places, use scala-logging.

Here is a simple application which shows a difference between discussed logging using default configurations:

import com.typesafe.scalalogging._

case object DummyMessage

class DummyActor extends Actor with ActorLogging with StrictLogging {
  override def receive = {
    case DummyMessage =>"I am ActorLogging")"I am StrictLogging")

object Main extends App {
  val system = ActorSystem("main")

  val dummy = system.actorOf(Props(new DummyActor))
  dummy ! DummyMessage
sbt run Main
[info] Running Main
[INFO] [03/20/2016 10:41:58.901] [] [akka://main/user/$a] I am ActorLogging
10:41:58.906 [] INFO  DummyActor - I am StrictLogging