SLF4J:类路径包含多个SLF4J绑定.消息打印在控制台上 [英] SLF4J: Class path contains multiple SLF4J bindings. message printed on console

查看:558
本文介绍了SLF4J:类路径包含多个SLF4J绑定.消息打印在控制台上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在控制台上打印日志,并将它们写到文件中.在使用akka记录器的scala项目中,这是我的 build.sbt

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")

这是我的代码的一部分

import akka.event.Logging

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

当我在打印消息后在sbt中运行程序时

when i run my program in sbt following message printed

SLF4J:类路径包含多个SLF4J绑定. SLF4J:找到 绑定在[jar:文件:/home/sara/.ivy2/cache/org.slf4j/slf4j -简单/jars/slf4j-简单-1.7.12.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J:在[jar:文件: /home/sara/.ivy2/cache/ch.qos.logback/logback-经典/罐子 /登录-经典-1.0.9.jar!/org/slf4j/impl/ [StaticLoggerBinder.class] SLF4J:请参阅http: //www.slf4j.org/codes.html#multiple_bindings进行解释. SLF4J:实际绑定的类型为[org.slf4j.impl.SimpleLoggerFactory] [ArteciateActorSystem-akka.actor.默认-dispatcher-3]信息 akka.event.slf4j.Slf4jLogger-Slf4jLogger 已开始[ArteciateActorSystem-akka.actor. 默认-dispatcher-2]信息 models.AdminUserModels.AdminUserModelsActors.RegularAdminWriteMongoActor -收到RegularAdminWriteInMongo消息

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

在打印完我的其他println语句之后,请帮助我如何停止显示此消息,也请不要将我的问题标记为重复,因为在我调查它之前它曾被询问过,但它不能解决我的问题..请帮助谢谢

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

推荐答案

该错误消息已经告诉您您需要了解的所有内容.消息中提供的链接( http://www.slf4j.org/codes.html#multiple_binding )说:

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旨在一次绑定一个且仅一个基础日志框架.如果类路径上存在多个绑定,SLF4J将发出警告,列出这些绑定的位置.

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.

您的类路径包含SLF4J的两个绑定:

Your classpath includes two bindings for SLF4J:

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

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

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

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

总结:从您的依赖项中删除slf4j-simple,logback-classic就足够了.

这篇关于SLF4J:类路径包含多个SLF4J绑定.消息打印在控制台上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆