How to implement “configureAndWatch” in log4j2

╄→尐↘猪︶ㄣ 提交于 2019-12-08 17:28:15

问题


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:


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>


来源:https://stackoverflow.com/questions/32843757/how-to-implement-configureandwatch-in-log4j2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!