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

丶灬走出姿态 提交于 2019-12-04 19:31:30

问题


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.


回答1:


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");



回答2:


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.



来源:https://stackoverflow.com/questions/6689887/how-to-force-log4j-load-xml-config-from-non-src-folder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!