In log4j2, monitorInterval
attribute is available for Configuration
element. I tried to read about the performance impact of this attribute but couldn't find any source anywhere. So, I have multiple questions regarding monitorInterval
attribute.
I would like to know, what performance impact it has by specifying a small value as 5
(5 seconds) and a large value let's say as 3000
(5 minutes) in Configuration
element?
What exactly happens? Does that mean, it will automatically detect every time a specified interval of time has elapsed?
Is there any way to force log4j2 to reload configuration right away via configuration files (XML, JSON, YAML, PROPERTIES), not programmatic reconfiguration?
It used to be the case that there was a small performance impact. Concretely, Log4j2 would occasionally check the lastModified
time of the configuration file when processing a log event. It was clever enough not to do that on every event but only when enough time had passed since the last time it checked: only once every monitorInterval
seconds.
Since Log4j 2.5 it is different: there's a watcher background thread that occasionally wakes up and checks the lastModified
time of the configuration file. So now there's no impact on logging performance. (The reason for this change was actually not performance but accuracy: previously files would not roll over if until a something was logged, which could be much later than the rollover time.) See https://issues.apache.org/jira/browse/LOG4J2-1202 for details.
To force a configuration reload, apart from touching the configuration file and programmatic reconfiguration, you can use the JMX interface. Also take a look at the Configurator class in log4j-core. It has several methods that result in reconfiguration.
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