gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 02:51:05 25 4
gpt4 key购买 nike

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

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

从多个绑定(bind)到 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. 您可以使用 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"))

关于scala - 为什么 Scalatra 警告我有关 log4j 的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17644276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com