: Stackoverflow - How to redirect logging in akka?
: How to setup SLF4J and LOGBack in a web app - fast
: Stackoverflow - Akka (2.3.0) fails to load Slf4jEventHandler class with java.lang.ClassNotFoundException
: Akka - Logging
It is essentially import to write logs in the file system when you are tracking issues or benchmark your Akka program. And it is quite a surprise that Akka can not directly log into files.
To achieve this, you will also need logback and slf4j.
All the dependency for this issue are changing these days, the version of Akka matters much. How you do this may change slightly according to your own version, but still could hurt much (at least to me).
Here is some version info of mine:
- Akka: 2.3.4
resolvers += "Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.3.4",
"com.typesafe.akka" % "akka-slf4j_2.10" % "2.3.4",
"ch.qos.logback" % "logback-classic" % "1.0.13",
In your /src/resources/application.conf, change default logger to Slf4jLogger.
loglevel = "DEBUG"
loggers = ["akka.event.slf4j.Slf4jLogger"]
Create a file named
logback.xml in /src/main/resources to config logback.
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<appender-ref ref="FILE" />
The destination of log is in file element.
The pattern of each line is set in pattern element.
Other config could refer to Logback's official document.
There is one thing show be pointed out: the date time in the pattern
%d, is not the time when program call
Log.info(msg) but the time when the line is written.