且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用自定义文件而不是log4j.properties

更新时间:2023-11-14 17:47:04

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

使用此一次;您只需通过系统参数指定log4j文件的路径:

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


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..

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