gpt4 book ai didi

java - log4j配置与jboss7问题

转载 作者:行者123 更新时间:2023-12-01 14:59:32 32 4
gpt4 key购买 nike

java代码

 public static synchronized void init(String log4jXMLPath) //throws ServletException
{
try
{
if (!initialized) // set the global RepositorySelector
{
defaultRepository = LogManager.getLoggerRepository();
RepositorySelector theSelector = new AppRepositorySelector();
**LogManager.setRepositorySelector(theSelector, guard);**
initialized = true;
}
Hierarchy hierarchy = new Hierarchy(new RootLogger(Level.DEBUG));
//loadLog4JConfig(servletContext, hierarchy);
loadLog4JConfig(hierarchy, log4jXMLPath);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
repositories.put(loader, hierarchy);
}
catch (Exception e)
{

e.printStackTrace();
}
}

LogManager.setRepositorySelector(theSelector, Guard); java 代码中的这一行抛出错误

堆栈跟踪

18:17:11,189 ERROR [stderr] (MSC service thread 1-2) java.lang.IllegalArgumentException: Attempted to reset the LoggerFactory without possessing the guard.
18:17:11,190 ERROR [stderr] (MSC service thread 1-2) at org.apache.log4j.LogManager.setRepositorySelector(LogManager.java:164)
18:17:11,191 ERROR [stderr] (MSC service thread 1-2) at com.mportal.logger.api.AppRepositorySelector.init(AppRepositorySelector.java:73)
18:17:11,192 ERROR [stderr] (MSC service thread 1-2) at com.mportal.logger.api.MPLoggerImpl.loadLogInstance(MPLoggerImpl.java:64)
18:17:11,192 ERROR [stderr] (MSC service thread 1-2) at com.mportal.logger.api.MPLoggerImpl.<init>(MPLoggerImpl.java:38)
18:17:11,192 ERROR [stderr] (MSC service thread 1-2) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
18:17:11,193 ERROR [stderr] (MSC service thread 1-2) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
18:17:11,194 ERROR [stderr] (MSC service thread 1-2) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
18:17:11,194 ERROR [stderr] (MSC service thread 1-2) at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

如何解决这个问题?请给出解决方案。

最佳答案

LogManager.setRepositorySelector(theSelector, guard);

只能使用一个守卫,使用不同的守卫对象会导致观察者错误:

java.lang.IllegalArgumentException: Attempted to reset the LoggerFactory without possessing the guard.

应该可以将 null 作为参数传递给函数。或者简单地保存对初始设置防护的引用。

文档指出:

最初守卫为空。如果守卫为空,则调用此方法将设置记录器工厂和守卫。以下调用将抛出 IllegalArgumentException,除非之前设置的防护作为第二个参数传递。

关于java - log4j配置与jboss7问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13879600/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com