Search code examples
scalaloggingakkalogback

Logging to file in Scala/akka: ClassNotFoundException: akka.event.slf4j.Slf4jLoggingFilter


I have searched quite a bit but could not find a working solution. Could someone please help me?

akka {
     event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
     loggers = ["akka.event.slf4j.Slf4jLogger"]
     loglevel = "DEBUG"
     logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
     stdout-loglevel = "WARNING"
     actor {
       debug {
         receive = on
         lifecycle = off
       }
     }
}

and I have added the following to build.sbt in the hope that one of them solves the issue:

libraryDependencies ++= Seq (
  "com.typesafe.akka" %% "akka-actor" % "2.4.1",   // akka actors
  "ch.qos.logback" % "logback-classic" % "1.1.3",  //logback, in order to log to file
  "com.typesafe.scala-logging" % "scala-logging-slf4j_2.11" % "2.1.2",
  "com.typesafe.akka" % "akka-slf4j_2.11" % "2.4.1",   // needed for logback to work
  // and my other dependencies
)

and I have tried with different suggestions I found for logback.xml, the last of which is:

<configuration>
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>logs/filename.log</file>
        <encoder>
            <pattern>%date %level %msg%n</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <maxIndex>10</maxIndex>
            <FileNamePattern>logs/filename.log.%i.gz</FileNamePattern>
        </rollingPolicy>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <maxFileSize>20MB</maxFileSize>
        </triggeringPolicy>
    </appender>
    <root level="info">
        <appender-ref ref="FILE" />
    </root>
</configuration>

EDIT: My complete dependencies are as follows (ps: I currently have both lift and salat for de/serialization, but that's a different story):

libraryDependencies ++= Seq (
  "org.scala-lang" % "scalap" % scalaVersion.value, 
  "com.typesafe.akka" %% "akka-actor" % "2.4.1",   
  "ch.qos.logback" % "logback-classic" % "1.1.3",  
  "com.typesafe.scala-logging" % "scala-logging-slf4j_2.11" % "2.1.2",
  "com.typesafe.akka" %% "akka-slf4j" % "2.4.1",  
  "com.github.sstone" %% "amqp-client" % "1.5", 
  "net.liftweb" %% "lift-json" % "2.6.2",
  "net.liftweb" %% "lift-json-ext" % "2.6.2",    
  "org.scalatest" %% "scalatest" % "2.2.4" % "test",
  "com.novus" %% "salat" % "1.9.9"
)

Solution

  • So you use "com.novus" %% "salat" % "1.9.9" which depends on salat-util % 1.9.9, which depends on org.slf4j % slf4j-api % 1.7.2. Akka "com.typesafe.akka" %% "akka-slf4j" % "2.4.1" depends on 1.7.12. Make sure that you need the whole salat package. Probably you could find a way of using only part of it, or configure logging in different way, or wait for update from Salat developers.