How to force log4j load xml config from non src fo

2019-03-26 06:07发布

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.

标签: java xml log4j
2条回答
一夜七次
2楼-- · 2019-03-26 06:43

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.

查看更多
姐就是有狂的资本
3楼-- · 2019-03-26 06:45

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");
查看更多
登录 后发表回答