如何实现“configureAndWatch”在log4j2中 [英] How to implement "configureAndWatch" in log4j2

查看:1161
本文介绍了如何实现“configureAndWatch”在log4j2中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

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

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

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

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

BasicConfigurator.configure()
BasicConfigurator.resetConfiguration()

如何在 log4j2 中实现这一目标?请帮忙。谢谢。

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

推荐答案

每个Log4j2文档
https://logging.apache.org/log4j/2.x/manual/configuration.html

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


当从文件配置时,Log4j能够自动检测配置文件的更改并重新配置自身。如果在配置元素上指定了monitorInterval属性并将其设置为非零值,则下次评估和/或记录日志事件时将检查该文件,并且自上次检查后已经过了monitorInterval。下面的示例显示了如何配置属性,以便仅在至少30秒后检查配置文件的更改。最小间隔为5秒。

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>

这篇关于如何实现“configureAndWatch”在log4j2中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆