How to use custom file instead of log4j.properties

自作多情 提交于 2019-12-19 04:18:42

问题


I'm using log4j in my java project. Instead of log4j.properties, i want to configure another file... Can anyone help me... Thanks in advance..


回答1:


org.apache.log4j.LogManager.resetConfiguration( );
if ( System.getProperty( "log4j.config" ) != null ) {
    DOMConfigurator.configureAndWatch( System.getProperty( "log4j.config" ) );
}
else {
    DOMConfigurator.configure( Loader.getResource( "log4j.properties" ) );
}

Use this one time; you only have to specify the path to your log4j file via system paramaters:

-Dlog4j.config=/path/to/your/log4j.properties



回答2:


This is a FAQ.

Just use java -Dlog4j.configuration=your/file/path.properties. See http://logging.apache.org/log4j/1.2/manual.html#defaultInit for details about this system property.




回答3:


try

PropertyConfigurator.configure("configFilename")


来源:https://stackoverflow.com/questions/7595025/how-to-use-custom-file-instead-of-log4j-properties

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