ClassNotFoundException when adding slf4j to Akka

When adding to a Akka project I got the following error java.lang.ClassNotFoundException: akka.event.slf4j.Slf4jLogger. I double checked my configuration and the Akka documentation. The documentation says the following:

Akka provides a logger for SL4FJ. This module is available in the ‘akka-slf4j.jar’. It has one single dependency; the slf4j-api jar. In runtime you also need a SLF4J backend, we recommend Logback.

No success.

After some Googling I found out that the akka-slf4j library is required in addition to the logback-classic library.

These dependencies need to be added to the build.sbt configuration:

libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.1.2"

libraryDependencies += "com.typesafe.akka" %% "akka-slf4j" % "2.3.6"

This is the relevant part of the Akka configuration:

akka {
	loggers = ["akka.event.slf4j.Slf4jLogger"]
	loglevel = "DEBUG"
	logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"

To be complete, this is the logback.xml configuration:

	<!-- Properties are set below, alternatively they can be set as system 
	     properties or passed as command line arguments -->
	<property name="LOG_HOME" value="logs" />
	<property name="LOG_FILE_NAME" value="application.log" />

	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
			<pattern>%date{ISO8601} %-5level %logger{36} %X{sourceThread} - %msg%n

	<appender name="FILE" class="ch.qos.logback.core.FileAppender">
			<pattern>%date{ISO8601} %-5level %-5level %logger{36} %X{sourceThread} - %msg%n</pattern>

	<root level="DEBUG">
		<appender-ref ref="STDOUT" />
		<appender-ref ref="FILE" />

Hope this helps someone.

Leave a Reply

Your email address will not be published. Required fields are marked *