我试图让某种类型的日志记录在 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。