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..
Asked
Active
Viewed 7,111 times
3 Answers
8
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.

JB Nizet
- 678,734
- 91
- 1,224
- 1,255
-
Property value should be a valid URL. The correct way is: `-Dlog4j.configuration=file:your/file/path.properties` – Nolequen Apr 04 '17 at 07:45
7
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
-
You are welcome; could you please upvote my answer or even set the "solved hook" if it helped? Thanks! – Andreas Sep 29 '11 at 12:52