Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
OrganizationEventAdvent CalendarQiitadon (β)
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

Akka - Log into files

[1]: Stackoverflow - How to redirect logging in akka?
[2]: How to setup SLF4J and LOGBack in a web app - fast
[3]: Stackoverflow - Akka (2.3.0) fails to load Slf4jEventHandler class with java.lang.ClassNotFoundException
[4]: 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

Add dependency

In your build.sbt

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",

Config Akka

In your /src/resources/application.conf, change default logger to Slf4jLogger.

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

Config logback

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 -->

    <root level="DEBUG">
        <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.

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Help us understand the problem. What are the problem?