如何在log4j2中实现"configureAndWatch"

How to implement "configureAndWatch" in log4j2

log4j中,有一个功能configureAndWatch(如下所述)无需重新启动应用程序服务器,可以修改日志阈值级别,默认延迟。

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

这在 log4j2 中也可以吗?如果是,那么如何实现?

此外,下面是用于设置和清理 log4j 设置的代码行。

BasicConfigurator.configure()
BasicConfigurator.resetConfiguration()

如何在 log4j2 中实现?请帮忙。谢谢。

根据 Log4j2 文档 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>