i would like to turn of my debug statements at runtime in log4j2. According to the documentation we can do this. I kept my log4j.xml file in default package and then made jar out of it. Since I cannot modify jar i specified xml file using Dlog4j.configuration=/path/to/log4j.xml. However,this is not working. I Tried everything using file:// uri to all the combination, still it is not picking the xml.
Use LogManager. resetConfiguration(); to clear the current config and configure it again. Another approach is to build a new appender and replace the old one with it (most appenders don't support changing their config).
System. setProperty("{my. log", "C:/logfile. log");
The system property to specify the config file location is different from log4j-1.x. In log4j2, the property is "log4j.configurationFile".
So if the config is in a jar file you would use:
-Dlog4j.configurationFile=jar:file:///C:/path/to/jarfile.jar!/path/to/log4j2.xml
(I assume you have the monitorInterval
set in your configuration as documented here: http://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticReconfiguration)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With