Eric Kolotyluk
Eric Kolotyluk

Reputation: 2243

Why is logging in Akka so different from Play?

I feel really stupid. When I read the logging documentation in Akka and then read the logging documentation in Play, they seem like two entirely different systems, implemented by two different teams, who have never met each other.

From my research, I believe they both use LogBack, but Akka seems to go out of its way to hide that fact.

I want to share some common code between my Akka and Play code, that incorporates common logging, but for the life of me I cannot see any easy solution from either the Akka/Play documentation or scaladoc:

Does anyone know of any examples of what logging in the Common code should look like?

Upvotes: 1

Views: 94

Answers (2)

Eric Kolotyluk
Eric Kolotyluk

Reputation: 2243

After mulling things over a bit, here is the kind of answer I was looking for. It may not be right, so perhaps someone can correct me if I am wrong. He

Akka

class MyActor extends Actor with ActorLogging {
  log.info("Hello Akka")
}

Play

import play.api.Logger

val logger = Logger(this.getClass())
logger.info("Hello Play")

Common

import org.slf4j.Logger
import org.slf4j.LoggerFactory

val logger = LoggerFactory.getLogger(this.getClass());
logger.info("Hello Common");

Configuration

Of course configuration is important too, such as

akka {
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  loglevel="DEBUG"
}

et al, but that was not the answer I was looking for at the time. However, that would have been my next question, so thanks to @pere-villega

Upvotes: 0

Pere Villega
Pere Villega

Reputation: 16439

As per documentation you can plug Akka to SFL4J:

akka {
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  loglevel="DEBUG"
}

and use your Play logback configuration. This means your common code should do the same.

Upvotes: 2

Related Questions