按需重新加载log4j2配置 [英] Reload log4j2 configuration on demand

查看:1056
本文介绍了按需重新加载log4j2配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将log4j2.xml配置文件设置为每30秒检查一次:

I have my log4j2.xml config file set to be checked every 30 seconds:

<Configuration status="WARN" monitorInterval="30">
    ...
</Configuration>

是否可以通过编程方式告诉log4j2检查配置中的更改而不是超时?

Is it possible to programmatically tell log4j2 to check for changes in the configuration instead of having a timeout?

NB 我不想以编程方式加载指定配置文件的配置,我只想告诉log4j2检查配置文件之前已加载,就像monitorInterval已过期一样。

N.B. I don't want to programmatically load the configuration specifying the config file, I just want to tell log4j2 to check the config file that has been loaded before as if the monitorInterval expired.

谢谢!

推荐答案

看起来我找到了解决方案:

It looks like I've found the solution:

((org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false)).reconfigure();

有人看到任何错误/副作用吗?

Does anyone see anything wrong/side-effects with this?

这篇关于按需重新加载log4j2配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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