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