Generally, adding a log4j.properties file to the classpath is all that needed to bootstrap your Log4J runtime. In certain cases though you might want to override this behaviour.

I needed to do this recently and it took me a while to find out how to do it in the Log4J docs, so I though I’d make a note of how to do it here.

To specify a file that Log4J will use instead of the default, pass its details as a system property when starting the JVM as follows:


java -Dlog4j.configuration=resources/log4j_dev.properties

The above example will load the log4j_dev.properties file from within the resources folder in the classpath. A file URL may also be specified:


java -Dlog4j.configuration=file:/resources/log4j_dev.properties

This will cause the log4j_dev.properties file to be loaded from the resources folder at the root of the file system.