【发布时间】:2022-01-19 23:45:10
【问题描述】:
我正在将应用程序从 log4j 1.2.17 转换为 2.16.0,看起来在 log4j2 中 LogManager 中不再有 setRepositorySelector() 方法。我无法按原样使用 log 1.x 桥接器,因为该项目不符合迁移文档中列出的要求。
以下功能是否有任何 log4j2 解决方法?原代码不是我写的,我只是更新一下。
//The "guard" is a simple object that protects against re-setting of the
//LoggerFactory by anyone but the one who set it first with a particular
//"guard". Basically, this would allow a container to set the LoggerFactory,
//but disallow applications running in the container from changing it. If
//the container holds a handle on the "guard" object, then it alone can
//change the LoggerFactory. If no one holds a handle on the "guard" object,
//then no one can change the LoggerFactory once it is set the first time.
Object guard = new Object();
try {
LogManager.setRepositorySelector(new ContextJNDISelector(), guard);
}catch(Exception e){
System.out.println("Exception, " + CLASS_NAME + ".contextInitialized(): " + e.getMessage());
//e.printStackTrace();
}
【问题讨论】: