Setting logback.xml path programmatically

后端 未结 5 1116
我在风中等你
我在风中等你 2020-12-02 13:27

I know I can set the logback.xml path like this:

Specifying the location of the default configuration file as a system property

You may specif

5条回答
  •  离开以前
    2020-12-02 13:49

    You could use:

    System.setProperty("logback.configurationFile", "/path/to/config.xml");
    

    But it would have to happen before logback is loaded, i.e. something like:

    class Main {
      static { System.setProperty("logback.configurationFile", "/path/to/config.xml");}
      private final Logger LOG = LoggerFactory.getLogger(Main.class);
    
      public void main (String[] args) { ... }
    }
    

    Note: I have not tested it but it should work.

提交回复
热议问题