How to implement “configureAndWatch” in log4j2

2019-06-20 07:33发布

In log4j, there is a feature configureAndWatch (as mentioned below) where without application server restart, log threshold level can be modified with default delay.

org.apache.log4j.xml.DOMConfigurator.configureAndWatch(log4j.xml path);

Is this possible in log4j2 as well ? If yes, then how can this be achieved ?

Also, below are lines of code for setting up and cleaning up log4j setup.

BasicConfigurator.configure()
BasicConfigurator.resetConfiguration()

How can this be achieved in log4j2 ? Please help. Thanks.

1条回答
forever°为你锁心
2楼-- · 2019-06-20 08:13

Per Log4j2 documentation https://logging.apache.org/log4j/2.x/manual/configuration.html

When configured from a File, Log4j has the ability to automatically detect changes to the configuration file and reconfigure itself. If the monitorInterval attribute is specified on the configuration element and is set to a non-zero value then the file will be checked the next time a log event is evaluated and/or logged and the monitorInterval has elapsed since the last check. The example below shows how to configure the attribute so that the configuration file will be checked for changes only after at least 30 seconds have elapsed. The minimum interval is 5 seconds.

<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="30">
...
</Configuration>
查看更多
登录 后发表回答