为什么Scalatra警告我有关log4j的信息

时间:2013-07-14 22:06:10

标签: scala logging log4j logback scalatra

我正在尝试在Scalatra中使用某种类型的日志记录。我只是按照http://www.scalatra.org/2.2/guides/monitoring/logging.html中的说明操作。在使用container:start启动后运行sbt时,我在控制台中看到以下内容,多条消息看起来不正确:

据我所知,我正在尝试使用logback,但稍后会加载log4j。这不是我期待的行为,但这正是我所看到的。

从多个绑定到log4j警告(我没有在这个应用程序的任何地方添加log4j):

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/foo/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.6.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/foo/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.0.11.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.Log4jLoggerFactory]
Null identity service, trying login service: null
Finding identity service: null
[info] started o.e.j.w.WebAppContext{/v1,[file:/Volumes/Macintosh%20HD%202/Dropbox/Projects/scalatra-test/src/main/webapp/]}
[info] started o.e.j.w.WebAppContext{/v1,[file:/Volumes/Macintosh%20HD%202/Dropbox/Projects/scalatra-test/src/main/webapp/]}
log4j:WARN No appenders could be found for logger (org.scalatra.servlet.ScalatraListener).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

不完全确定这里的问题是什么。我只想:

  • 将一些调试语句记录到STDOUT(假设它将转到我从sbt开始的术语)
  • 将一些调试语句记录到我可以简单地尾随
  • 的文件中

我的依赖项在build.scala中如下所示:

libraryDependencies ++= Seq(
    "org.scalatra" %% "scalatra" % ScalatraVersion,
    "org.scalatra" %% "scalatra-scalate" % ScalatraVersion,
    "org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",
    "ch.qos.logback" % "logback-classic" % "1.0.6" % "runtime",
    "org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "container",
    "org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar")),
    "org.mongodb" %% "casbah" % "2.6.1",
    "org.scalatra" %% "scalatra-json" % "2.2.1",
    "org.json4s"   %% "json4s-native" % "3.2.4",
    //"org.json4s" %% "json4s-jackson" % "3.2.4",
    "org.scalatra" %% "scalatra-swagger"  % "2.2.1",
    "commons-codec" % "commons-codec" % "1.8"
  ),

这里有什么东西可能还需要log4j并且这会覆盖logback吗?

是否也可以指示sbt从这个项目中完全排除log4j?我找不到什么需要它作为依赖,但它应该使用logback而不是。

1 个答案:

答案 0 :(得分:4)

  1. 您可以使用sbt-dependency-graph插件来检测所依赖的内容 在log4j。
  2. 并将其从您的构建中排除。例如:

    libraryDependencies += "org.scalatra" %% "scalatra" % "2.2.1" exclude("org.slf4j", "log4j12")
    

    libraryDependencies += "org.scalatra" %% "scalatra" % "2.2.1" excludeAll(ExclusionRule(organization = "org.slf4j"))
    
相关问题