3

我想使用 slf4j 进行日志记录,基于logging doc。这些配置应更改为application.conf

akka {
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
}

我正在使用application.properties而不是application.conf

akka.loggers[0]=akka.event.slf4j.Slf4jLogger
akka.logging-filter=akka.event.slf4j.Slf4jLoggingFilter

但是上面的配置并没有改变akka.loggers值(该值仍然是默认值:)akka.event.Logging$DefaultLogger

打印所有配置:

"loggers" : [
    # reference.conf @ jar:file:/home/user/.m2/repository/com/typesafe/akka/akka-actor_2.12/2.5.18/akka-actor_2.12-2.5.18.jar!/reference.conf: 17
    "akka.event.Logging$DefaultLogger"
],
# application.properties @ file:/home/user/workspace/x-platform/target/test-classes/application.properties
"loggers[0]" : "akka.event.slf4j.Slf4jLogger",
# application.properties @ file:/home/user/workspace/x-platform/target/test-classes/application.properties
"logging-filter" : "akka.event.slf4j.Slf4jLoggingFilter",

所以我的问题是:我如何设置/更改列表 prpperty 的值application.properties

我在2.5.18Java 中使用 akka。

4

1 回答 1

0

你试过这个 parseString 吗?

val customConf = ConfigFactory.parseString("""
      akka {
        loggers = ["akka.event.slf4j.Slf4jLogger"]
        logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
      }
      """)
val system = ActorSystem("MySystem", ConfigFactory.load(customConf))

或将自定义配置与通常的配置相结合

Config myConfig =ConfigFactory.parseString("loggers=['akka.event.slf4j.Slf4jLogger']");
Config regularConfig = ConfigFactory.load();
Config combined = myConfig.withFallback(regularConfig);
于 2018-12-03T21:25:20.133 回答