How to force log4j load xml config from non src folder?

后端 未结 2 746
遇见更好的自我
遇见更好的自我 2021-02-14 21:26

Is it possible to have log4j.xml loaded from a different dir than source root and how? (programmatically?) Meaning that it\'s somewhere in FS not just in classpath.

相关标签:
2条回答
  • 2021-02-14 21:49

    Using DOMConfigurator you can specify the the XML file used to configure log4j.

    DOMConfigurator.configure("/path/to/log4j.xml");
    

    For log4j.properties you can do the same thing with PropertyConfigurator.

    PropertyConfigurator.configure("/path/to/log4j.properties");
    
    0 讨论(0)
  • 2021-02-14 21:58

    This might not be the best way, but you can specify the location of the file by setting the java property log4j.configuration=path/to/config/file. For example, you can specify this directly to the java command with java -Dlog4j.configuration=path.

    0 讨论(0)
提交回复
热议问题