log4j2 中的 PropertyConfigurator [英] PropertyConfigurator in log4j2

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

问题描述

我正在将 log4j 1.2.8 迁移到 log4j 2.3.一切正常,除了我没有找到任何替代 PropertyConfigurator.

I'm migrating log4j 1.2.8 to log4j 2.3. Everything works fine, beside that I'm not finding any any alternative for the PropertyConfigurator.

是否有另一个类来处理 PropertyConfigurator 之前所做的事情?

Is there another class to take care of what the PropertyConfigurator did before?

推荐答案

也许这对你有帮助?

如何使用特定的配置文件在代码中重新配置 log4j2?请参见下面的示例.请注意,此 LoggerContext 类不是公共 API 的一部分,因此您的代码可能会因任何次要版本而中断.

// import org.apache.logging.log4j.core.LoggerContext;

LoggerContext context = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false);
File file = new File("path/to/a/different/log4j2.xml");


// this will force a reconfiguration
context.setConfigLocation(file.toURI());**

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

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