Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SLF4J: Class path contains multiple SLF4J bindings. message printed on console

I want to print logs on console and also write them in a file. In my scala project using akka loggers here is my build.sbt

libraryDependencies ++= Seq("org.mongodb" %% "casbah" % "2.8.0",
                            "org.slf4j" % "slf4j-simple" % "1.7.12",
                            "org.elasticsearch" % "elasticsearch" % "1.5.0",
                            "org.scalatest" %% "scalatest" % "2.2.1" % "test"
                        withSources() withJavadoc(),
                        "org.easymock" % "easymock" % "3.1" withSources() withJavadoc(),
                        "org.mockito" % "mockito-all" % "1.9.5",
                        "com.typesafe.akka" %% "akka-actor" % "2.3.6",
                        "ch.qos.logback" % "logback-classic" % "1.0.9",
                        "com.typesafe.akka" %% "akka-slf4j" % "2.3.9")

and here is a part of my code

import akka.event.Logging

val log = Logging(context.system, this)
case RegularAdminWriteInMongo =>
    log.debug("writing to mongo")
    log.info("message received RegularAdminWriteInMongo")

when i run my program in sbt following message printed

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar: file: /home/sara / .ivy2 / cache / org.slf4j / slf4j - simple / jars / slf4j - simple - 1.7.12.jar!/org/slf4j / impl / StaticLoggerBinder.class] SLF4J: Found binding in [jar: file: /home/sara / .ivy2 / cache / ch.qos.logback / logback - classic / jars / logback - classic - 1.0.9.jar!/org/slf4j / impl / StaticLoggerBinder.class] SLF4J: See http: //www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type[org.slf4j.impl.SimpleLoggerFactory] [ArteciateActorSystem - akka.actor. default -dispatcher - 3] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started[ArteciateActorSystem - akka.actor. default -dispatcher - 2] INFO models.AdminUserModels.AdminUserModelsActors.RegularAdminWriteMongoActor - message received RegularAdminWriteInMongo

after that my other println statements are printed ,Please help me how to stop displaying this message ,also please do not mark my question as duplicate as its been asked before i looked into it but it does not solve my problem..please help thanks

like image 723
swaheed Avatar asked Apr 16 '15 09:04

swaheed


People also ask

What is SLF4J bindings?

Bindings are basically implementations of a particular SLF4J class meant to be extended to plug in a specific logging framework. By design, SLF4J will only bind with one logging framework at a time. Consequently, if more than one binding is present on the classpath, it will emit a warning.

What is SLF4J reload4j?

2022-01-25 - Release of SLF4J 1.7. The reload4j project is a fork of Apache log4j version 1.2. 17 with the goal of fixing pressing security issues. It is intended as a drop-in replacement for log4j version 1.2. 17. By drop-in, we mean the replacement of log4j.


1 Answers

The error message already tells you everything you need to know. The link provided in the message (http://www.slf4j.org/codes.html#multiple_binding) says:

SLF4J API is designed to bind with one and only one underlying logging framework at a time. If more than one binding is present on the class path, SLF4J will emit a warning, listing the location of those bindings.

Your classpath includes two bindings for SLF4J:

/home/sara/.ivy2/cache/org.slf4j/slf4j-simple/jars/slf4j-simple-1.7.12.jar

and

/home/sara/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.0.9.jar

Make sure there is only one binding on your classpath and the warning will not be shown again.

To summarize: Remove slf4j-simple from your dependencies, logback-classic is enough.

like image 140
sheltem Avatar answered Oct 16 '22 01:10

sheltem