Scala 中的 Akka SLF4J 和 logback
Akka SLF4J and logback in Scala
我正在尝试为我的 akka actor 系统设置一些基本日志记录,但到目前为止我只获得标准日志和 none 我添加的日志或输出文件。我跟随 akka docs for logging 并设置了以下内容:
我将这些依赖项添加到 build.sbt 文件
"com.typesafe.akka" %% "akka-slf4j" % "2.3.14"
"ch.qos.logback" % "logback-classic" % "1.0.9"
我将其添加到 application.conf 文件
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "DEBUG"
}
logback.xml 在 src/main/resources
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<File>./logs/akka.log</File>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="FILE" />
</root>
</configuration>
这就是我希望做的日志记录
import akka.event.Logging
val log = Logging(context.system, classOf[TickActor])
log.info("Good Luck!")
我没有收到来自标准日志记录的失败消息,而且我无法找到与我已有的解决方案大不相同的其他解决方案。我已经尝试了 this question 中的建议。这似乎是我遇到的同一个问题,但这些建议没有用。我是不是错过了一步或配置有误?
除了缺失的 akka.logging-filter
设置外,一切看起来都是正确的。
它应该是这样的:
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "DEBUG"
logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
}
这是一个具有相同设置且日志记录工作的项目:application.conf and logback.xml。
来自docs的解释:
You need to enable the Slf4jLogger in the loggers element in the
Configuration. Here you can also define the log level of the event
bus. More fine grained log levels can be defined in the configuration
of the SLF4J backend (e.g. logback.xml). You should also define
akka.event.slf4j.Slf4jLoggingFilter in the logging-filter
configuration property. It will filter the log events using the
backend configuration (e.g. logback.xml) before they are published to
the event bus.
和
Warning! If you set the loglevel to a higher level than "DEBUG", any
DEBUG events will be filtered out already at the source and will never
reach the logging backend, regardless of how the backend is
configured.
你已经处理好了。
我正在尝试为我的 akka actor 系统设置一些基本日志记录,但到目前为止我只获得标准日志和 none 我添加的日志或输出文件。我跟随 akka docs for logging 并设置了以下内容:
我将这些依赖项添加到 build.sbt 文件
"com.typesafe.akka" %% "akka-slf4j" % "2.3.14" "ch.qos.logback" % "logback-classic" % "1.0.9"
我将其添加到 application.conf 文件
akka { loggers = ["akka.event.slf4j.Slf4jLogger"] loglevel = "DEBUG" }
logback.xml 在 src/main/resources
<configuration> <appender name="FILE" class="ch.qos.logback.core.FileAppender"> <File>./logs/akka.log</File> <encoder> <pattern>%d{HH:mm:ss.SSS} [%-5level] %msg%n</pattern> </encoder> </appender> <root level="info"> <appender-ref ref="FILE" /> </root> </configuration>
这就是我希望做的日志记录
import akka.event.Logging val log = Logging(context.system, classOf[TickActor]) log.info("Good Luck!")
我没有收到来自标准日志记录的失败消息,而且我无法找到与我已有的解决方案大不相同的其他解决方案。我已经尝试了 this question 中的建议。这似乎是我遇到的同一个问题,但这些建议没有用。我是不是错过了一步或配置有误?
除了缺失的 akka.logging-filter
设置外,一切看起来都是正确的。
它应该是这样的:
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "DEBUG"
logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
}
这是一个具有相同设置且日志记录工作的项目:application.conf and logback.xml。
来自docs的解释:
You need to enable the Slf4jLogger in the loggers element in the Configuration. Here you can also define the log level of the event bus. More fine grained log levels can be defined in the configuration of the SLF4J backend (e.g. logback.xml). You should also define akka.event.slf4j.Slf4jLoggingFilter in the logging-filter configuration property. It will filter the log events using the backend configuration (e.g. logback.xml) before they are published to the event bus.
和
Warning! If you set the loglevel to a higher level than "DEBUG", any DEBUG events will be filtered out already at the source and will never reach the logging backend, regardless of how the backend is configured.
你已经处理好了。