在Akka的application.properties中设置/更改列表属性

时间:2018-11-24 12:03:14

标签: akka typesafe-config application.properties

我想基于logging doc使用slf4j进行日志记录。这些配置应在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",

所以我的问题是:如何在application.properties中设置/更改列表属性的值?

我在Java上使用akka 2.5.18

1 个答案:

答案 0 :(得分: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);