log4j2中的PropertyConfigurator [英] PropertyConfigurator in log4j2
本文介绍了log4j2中的PropertyConfigurator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将log4j 1.2.8迁移到log4j 2.3.一切正常,除了
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的一部分,因此您的代码可能会随任何次要发行版而中断.
How do I reconfigure log4j2 in code with a specific configuration file? See the below example. Be aware that this LoggerContext class is not part of the public API so your code may break with any minor release.
// 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屋!
查看全文