Scala 未能加载类“;org.slf4j.impl.StaticLoggerBinder”的;来自SLF4J的消息错误
我正在使用Akka和Akka http开发一个简单的服务器 当我在IntelliJ中运行应用程序时,我总是在标准输出中收到以下错误消息:Scala 未能加载类“;org.slf4j.impl.StaticLoggerBinder”的;来自SLF4J的消息错误,scala,log4j,akka,slf4j,Scala,Log4j,Akka,Slf4j,我正在使用Akka和Akka http开发一个简单的服务器 当我在IntelliJ中运行应用程序时,我总是在标准输出中收到以下错误消息: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLogge
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
我在build.gradle中有以下依赖项:
compile 'org.scala-lang:scala-library:2.12.1'
compile 'com.typesafe.akka:akka-actor_2.12:2.4.17'
compile 'com.typesafe.akka:akka-stream_2.12:2.4.17'
compile 'com.typesafe.akka:akka-http_2.12:10.0.4'
compile 'com.typesafe.akka:akka-http-spray-json_2.12:10.0.4'
compile 'com.typesafe.akka:akka-slf4j_2.12:2.4.17'
我有application.conf,如下所示:
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "INFO"
stdout-loglevel = "INFO"
logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
...
}
最后,我使用如下日志记录:
object HttpServer extends App with JsonSupport {
override def main(args: Array[String]): Unit = {
val config = ConfigFactory.load()
implicit val system = ActorSystem(config.getString("application.actor-system"))
implicit val materializer = ActorMaterializer()
// needed for the future flatMap/onComplete in the end
implicit val executionContext = system.dispatcher
val logger = Logging(system, getClass)
有人知道我为什么总是收到这些错误声明吗?您需要提供一个SLF4J后端-Akka recommend Logback 这是通过将其添加到依赖项中来实现的,如下所示。您可能还希望将依赖项标记为
运行时
,因为编译时不需要它
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.1.3" % Runtime
请注意,这不是Akka的具体要求。
只是一个门面,总是需要一个日志后端。
还要注意,如果选择Logback,建议提供一个带有日志设置的Logback.xml
文件,请参阅以获取参考
关于Akka内的日志记录,您需要知道的是。这对我来说很有效-去掉了警告,但我得到了几个值得调试和信息日志的屏幕。上面答案中的docs链接很有帮助(基本上,添加
logback.xml
并根据需要进行配置)。“SLF4J只是一个门面,总是需要一个日志后端。”这句话非常重要。特别是对于那些来自其他语言(如Python)的人来说,Java日志提供了一个真正的地狱,因为它在主题和语句方面缺乏实用主义,例如,帮助很大。谢谢你,斯蒂法诺。