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

自闭症网瘾萝莉.ら 提交于 2020-01-02 01:18:12

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/29671133/slf4j-class-path-contains-multiple-slf4j-bindings-message-printed-on-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!