How to change log4j2 configuration file at runtime?

I would like to enable my debug statements at runtime in log4j2. According to the documentation, we can do this. I saved the log4j.xml file in the default package, and then made a jar from it. Since I cannot change the jar, I specified the xml file using Dlog4j.configuration = / path / to / log4j.xml. However, this does not work. I tried everything using the file: // uri for the whole combination, but it does not select xml.

+4
source share
2 answers

The system property for specifying the location of the configuration file is different from log4j-1.x. In log4j2, this is the "log4j.configurationFile" property.

, config jar, :

-Dlog4j.configurationFile=jar:file:///C:/path/to/jarfile.jar!/path/to/log4j2.xml

( , monitorInterval , : http://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticReconfiguration)

+3

:

<Configuration monitorInterval="60" >
+1

All Articles