gpt4 book ai didi

scala - 无法从 SLF4J 加载类 "org.slf4j.impl.StaticLoggerBinder"消息错误

转载 作者:行者123 更新时间:2023-12-01 16:15:41 25 4
gpt4 key购买 nike

我正在使用 Akka 和 Akka-http 开发一个简单的服务器。

当我在 IntelliJ 中运行应用程序时,我总是在 stdout 中收到以下错误消息:

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 docs推荐登录。

这是通过将其添加到您的依赖项中来实现的,如下所示。您可能还想将依赖项标记为运行时,因为编译时不需要它。

libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.1.3" % Runtime

请注意,这不是 Akka 的特定要求。<强> SLF4J只是一个外观,总是需要一个日志记录后端。

另请注意,如果您选择 Logback,建议提供包含日志记录设置的 logback.xml 文件,请参阅 this answer供引用。

关于 Akka 中的日志记录,您需要了解的所有信息都在 docs 中。 .

关于scala - 无法从 SLF4J 加载类 "org.slf4j.impl.StaticLoggerBinder"消息错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42598459/

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