How to make log4j load xml config from non src folder?

Is it possible that log4j.xml is loaded from a source other than the original root, and how? (programmatically?) Meaning that it is somewhere in the FS, not only in the classpath.

+8
java xml log4j
source share
2 answers

Using the DOMConfigurator , you can specify the XML file used to configure log4j.

DOMConfigurator.configure("/path/to/log4j.xml"); 

For log4j.properties you can do the same with PropertyConfigurator .

 PropertyConfigurator.configure("/path/to/log4j.properties"); 
+19
source share

This may not be the best way, but you can specify the location of the file by setting the java property log4j.configuration = path / to / config / file. For example, you can specify this directly in a java command using java -Dlog4j.configuration=path .

+3
source share

All Articles