Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to load class "org.slf4j.impl.StaticLoggerBinder" message error from SLF4J

I am developing a simple server using Akka and Akka-http.

I always get following error message in stdout when I run application into IntelliJ:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

I have the following dependencies in build.gradle:

compile 'org.scala-lang:scala-library:2.12.1'
compile 'com.typesafe.akka:akka-actor_2.12:2.4.17'
compile 'com.typesafe.akka:akka-stream_2.12:2.4.17'
compile 'com.typesafe.akka:akka-http_2.12:10.0.4'
compile 'com.typesafe.akka:akka-http-spray-json_2.12:10.0.4'
compile 'com.typesafe.akka:akka-slf4j_2.12:2.4.17'

And I have application.conf as given below:

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

And finally, I am using Logging like this:

object HttpServer extends App with JsonSupport {
  override def main(args: Array[String]): Unit = {

  val config = ConfigFactory.load()

  implicit val system = ActorSystem(config.getString("application.actor-system"))
  implicit val materializer = ActorMaterializer()

  // needed for the future flatMap/onComplete in the end
  implicit val executionContext = system.dispatcher

  val logger = Logging(system, getClass)

Can anyone know why I always get that errors statements?

like image 222
Sergio Rodríguez Calvo Avatar asked Mar 04 '17 16:03

Sergio Rodríguez Calvo


People also ask

What is SLF4J error?

This is a warning which is caused when there are no SLF4J bindings provided in the classpath. SLF4J: Failed to load class "org. slf4j. impl.

What is log4j over SLF4J?

log4j-over-slf4j. SLF4J ship with a module called log4j-over-slf4j. It allows log4j users to migrate existing applications to SLF4J without changing a single line of code but simply by replacing the log4j. jar file with log4j-over-slf4j.

What is SLF4J API jar?

API for SLF4J (The Simple Logging Facade for Java) which serves as a simple facade or abstraction for various logging frameworks, allowing the end user to plug in the desired logging framework at deployment time.

What is SLF4J jdk14?

slf4j is Simple Logging Facade for Java .


1 Answers

You need to provide a SLF4J backend - Akka docs recommend Logback.

This is achieved by adding it to your dependencies as per below. You might want to flag the dependency as Runtime as well, as it will not be needed compile-time.

libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.1.3" % Runtime

Please note this is not a specific requirement of Akka. SLF4J is only a facade and always requires a logging backend.

Also note that, in case you choose Logback, it is recommended to provide a logback.xml file with your logging settings, see this answer for a reference.

All you need to know about logging within Akka is in the docs.

like image 181
Stefano Bonetti Avatar answered Oct 10 '22 14:10

Stefano Bonetti