Ranjith
Ranjith

Reputation: 163

How to use custom file instead of 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..

Upvotes: 3

Views: 7416

Answers (3)

Andreas
Andreas

Reputation: 2309

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

Upvotes: 7

JB Nizet
JB Nizet

Reputation: 692231

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.

Upvotes: 8

ollins
ollins

Reputation: 1849

try

PropertyConfigurator.configure("configFilename")

Upvotes: 1

Related Questions