log4j2:异步记录器未启动

时间:2017-01-25 10:36:09

标签: asynchronous log4j2

我最近升级了我的应用程序以使用log4j2。我正在尝试使用其异步记录器功能。然而,看起来它没有创建一个。 按照Log4j Async config,它说,

  1. 要使所有记录器异步,请将disruptor jar添加到类路径中,并将系统属性Log4jContextSelector设置为org.apache.logging.log4j.core.async.AsyncLoggerContextSelector。 我还设置了状态=" trace"在log4j.xml中查看它是否配置并实例化异步记录器。但看起来它失败了。
  2.   

    2017-01-25 01:58:30,799主TRACE重新注册上下文(1/1):' AsyncContext @ 18b4aac2' org.apache.logging.log4j.core.async.AsyncLoggerContext@6bf08014   2017-01-25 01:58:30,800主要TRACE取消注册但找不到匹配的' org.apache.logging.log4j2:type = AsyncContext @ 18b4aac2'   2017-01-25 01:58:30,800主要TRACE取消注册,但没有找到匹配' org.apache.logging.log4j2的MBean:type = AsyncContext @ 18b4aac2,component = StatusLogger'   2017-01-25 01:58:30,800主要TRACE取消注册,但找不到匹配的' org.apache.logging.log4j2:type = AsyncContext @ 18b4aac2,component = ContextSelector'   2017-01-25 01:58:30,801主要TRACE取消注册,但找不到匹配的' org.apache.logging.log4j2:type = AsyncContext @ 18b4aac2,component = Loggers,name = '   2017-01-25 01:58:30,801主要TRACE取消注册,但找不到匹配' org.apache.logging.log4j2:type = AsyncContext @ 18b4aac2,component = Appenders,name = '   2017-01-25 01:58:30,801主要TRACE取消注册,但找不到匹配' org.apache.logging.log4j2:type = AsyncContext @ 18b4aac2,component = AsyncAppenders,name = '   2017-01-25 01:58:30,801主要TRACE取消注册,但找不到匹配' org.apache.logging.log4j2:type = AsyncContext @ 18b4aac2,component = AsyncLoggerRingBuffer'   2017-01-25 01:58:30,802主要TRACE取消注册,但找不到匹配的' org.apache.logging.log4j2:type = AsyncContext @ 18b4aac2,component = Loggers,name = ,subtype = RingBuffer& #39;   2017-01-25 01:58:30,803 main DEBUG注册MBean org.apache.logging.log4j2:type = AsyncContext @ 18b4aac2   2017-01-25 01:58:30,805 main DEBUG注册MBean org.apache.logging.log4j2:type = AsyncContext @ 18b4aac2,component = AsyncLoggerRingBuffer   2017-01-25 01:58:30,806 main DEBUG注册MBean org.apache.logging.log4j2:type = AsyncContext @ 18b4aac2,component = StatusLogger   2017-01-25 01:58:30,807 main DEBUG注册MBean org.apache.logging.log4j2:type = AsyncContext @ 18b4aac2,component = ContextSelector   2017-01-25 01:58:30,816 main TRACE使用默认的SystemClock作为时间戳。   2017-01-25 01:58:30,816主要TRACE使用DummyNanoClock进行纳秒时间戳。   2017-01-25 01:58:30,817主要DEBUG重新配置完成上下文[name = AsyncContext @ 18b4aac2]在URI /etc/opt/sun/im/default/config/log4j2.xml(org.apache.logging.log4j。 core.async.AsyncLoggerContext@6bf08014)带有可选的ClassLoader:null   2017-01-25 01:58:30,817主DEBUG Shutdown hook启用。注册一个新的。   2017-01-25 01:58:30,818主要DEBUG LoggerContext [name = AsyncContext @ 18b4aac2,org.apache.logging.log4j.core.async.AsyncLoggerContext@6bf08014]开始了。

    因为我没有看到类似"启动AsyncLogger disruptor"。

    1. 然后按照建议,我尝试使用asyncLogger标签,我可以看到它打印,

        

      2017-01-25 00:27:26,970主TRACE AsyncLoggerConfigDisruptor为此配置创建新的破坏程序。   2017-01-25 00:27:26,971主要TRACE属性AsyncLoggerConfig.WaitStrategy = TIMEOUT   2017-01-25 00:27:26,987 main DEBUG使用ringbufferSize = 4096启动此配置的AsyncLoggerConfig中断器,waitStrategy = TimeoutBlockingWaitStrategy,exceptionHandler = org.apache.logging.log4j.core.async.AsyncLoggerConfigDefaultExceptionHandler@7f284218 ...   2017-01-25 00:27:26,988主TRACE AsyncLoggerConfig [xmppd]开始...

      但是在以后的阶段,它会抛出未找到的课程的异常,

        

      2017-01-25 00:27:31,658主要错误无法在类类asgLogger的类类org.apache.logging.log4j.core.async.AsyncLoggerConfig中调用工厂方法。 java.lang.reflect.InvocationTargetException           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)           at java.lang.reflect.Method.invoke(Method.java:498)           在org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:132)           在org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:942)           在org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:882)           在org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:874)           在org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:498)           在org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:227)           在org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:239)           在org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:530)           在org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:603)           在org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:620)           在org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:226)           在org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:242)           at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)           在org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)           在org.apache.logging.log4j.LogManager.getLogger(LogManager.java:618)           在org.apache.logging.log4j.LogManager.getRootLogger(LogManager.java:652)           引起:java.lang.NoClassDefFoundError:com / lmax / disruptor / EventFactory           at org.apache.logging.log4j.core.config.AbstractConfiguration.getAsyncLoggerConfigDelegate(AbstractConfiguration.java:197)           在org.apache.logging.log4j.core.async.AsyncLoggerConfig。(AsyncLoggerConfig.java:81)           在org.apache.logging.log4j.core.async.AsyncLoggerConfig.createLogger(AsyncLoggerConfig.java:188)           ......还有23个   引起:java.lang.ClassNotFoundException:com.lmax.disruptor.EventFactory           at java.net.URLClassLoader.findClass(URLClassLoader.java:381)           at java.lang.ClassLoader.loadClass(ClassLoader.java:424)           at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:331)           at java.lang.ClassLoader.loadClass(ClassLoader.java:357)           ......还有26个

    2. 我已经验证过,我所包含的干扰罐有这个类。我正在使用disruptor-3.3.6.jar。

      另外如何验证异步记录器是否已启动?

      任何帮助都将不胜感激。

3 个答案:

答案 0 :(得分:0)

我需要进一步调查,但似乎Log4j2依赖于一个类com.lmax.disruptor.EventFactory,它在您正在使用的破坏程序版本中不再存在。你能用旧版吗? 3.3.2应该工作。

答案 1 :(得分:0)

添加 LMAX Disruptor 依赖项。要使用 AsyncLogger ,您的pom.xml应该像这样

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>
    <dependency> 
        <groupId>com.lmax</groupId>
        <artifactId>disruptor</artifactId>
        <version>3.3.7</version>
    </dependency>

进一步阅读:Performance of log4j2 compared to log4j1

答案 2 :(得分:0)

在您的Pom文件中添加以下依赖性:

<!-- Exclude Spring Boot's Default Logging -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Add Log4j2 Dependency -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>

        <dependency> 
             <groupId>com.lmax</groupId> 
             <artifactId>disruptor</artifactId> 
                     <version>3.3.7</version> 
        </dependency>