How can I configure system properties or logback configuration variables from typesafe config?

后端 未结 3 1614
死守一世寂寞
死守一世寂寞 2021-02-02 14:15

I have variables with defaults in my logback.xml configuration file, and I would like to be able to optionally set these variables from my typesafe config app

3条回答
  •  误落风尘
    2021-02-02 14:45

    I'm not familiar with Logback, but a normal Akka application ships with default settings in its reference.conf, and you override these settings in an application.conf. It sounds like you want to add a third layer of configuration, which is certainly your right!

    The easiest way I can see is to change your application.conf to include your foo.conf rather than the other way around. That way Akka will load the application.conf, which will then load foo.conf.

    But that may not work if you need a differently-named conf file for each JAR distribution. In which case I recommend you look into Merging Config Trees to programmatically load and combine configuration. Actually, Reading configuration from a custom location in the Akka Configuration docs is almost exactly what you want, except you will want to load myConfig from a classpath resource rather than by parsing a string (see the Typesafe Config docs to find out how to do that).

    Regarding the Logback configuration, like I said, I don't know Logback. But you can read values out an Typesafe configuration like so, and you can set the Logback root logger level like so.

提交回复
热议问题