0

我从 log4j 移动到 log4j2 并
在调用时看到以下异常堆栈:

private static final Logger LOG = LoggerFactory.getLogger(com.mine.pto.ejb_access.MyClass.class);

在应用程序内使用多个线程时,有时会引发异常。

知道我在 Log4j2 上做错了什么吗?

2015-10-13 16:18:48,029 ERROR Could not register mbeans javax.management.InstanceAlreadyExistsException: org.apache.logging.log4j2:type=1304568236,component=Loggers,name=com.mine.pto.ejb_access
at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:966)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324)
at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:513)
at org.apache.logging.log4j.core.jmx.Server.register(Server.java:375)
at org.apache.logging.log4j.core.jmx.Server.registerLoggerConfigs(Server.java:344)
at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:182)
at org.apache.logging.log4j.core.jmx.Server.reregisterMBeansAfterReconfigure(Server.java:143)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:372)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:426)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:442)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:138)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:147)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:175)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:102)
at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:42)
at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:285)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:305)
...
4

2 回答 2

0

也许迟到了,但尝试使用log4j2.disableJmx系统属性禁用 JMX,看看是否有帮助。在这里查看更多信息JMX

于 2022-01-19T21:01:51.803 回答
0

这可能是https://issues.apache.org/jira/browse/LOG4J2-1094的副本。

如果是这样,解决方法是LoggerFactory.getLogger()在启动任何线程之前调用。

于 2015-10-19T16:55:30.640 回答