简体   繁体   English

log4j2异步记录器线程未终止

[英]log4j2 asynchronous logger thread is not killed

I am creating a sample Log4j2 configuration with Asyn Appender, After the executing is complete the thread which is generated by AsyncAppender is not killed? 我正在使用Asyn Appender创建一个示例Log4j2配置,执行完成后,由AsyncAppender生成的线程不会被杀死吗? is it a bug or any configuration is explicit to kill the thread. 是Bug还是任何明确配置都可以杀死线程。

My sample summary Appender 我的样本摘要Appender

<!-- ####################### SUMMARY FILE APPENDER ####################### -->
    <RollingFile name="SUMMARY_ALL" fileName="./logs/summary.log"
        filePattern="logs/$${date:yyyy-MM}/summary-%d{yyyy-MM-dd-HH}-%i.log.gz">
        <PatternLayout>
            <pattern>%d{ISO8601} [%t] %p %c %L - %m%n</pattern>
        </PatternLayout>
        <Policies>
            <TimeBasedTriggeringPolicy interval="6"
                modulate="true" />
            <SizeBasedTriggeringPolicy size="10 MB" />
        </Policies>
    </RollingFile>

Sample Logger as below 样品记录仪如下

  <logger name="com.test.learn" level="DEBUG">
<appender-ref ref="Async" />
  </logger>

Sample code package com.test.learn; 示例代码包com.test.learn;

import org.apache.logging.log4j.LogManager; 导入org.apache.logging.log4j.LogManager;

public class TestLogger {
private static org.apache.logging.log4j.Logger log = LogManager
        .getLogger(TestLogger.class);

public static void main(String[] args) {
    log.info("testing logger");
}

} }

after this is executed, the java process should exit, but its not. 执行此操作后,java进程应退出,但不退出。 Can anyone please help me. 谁能帮帮我吗。

This will shut down the logging sub system and stop any async threads: 这将关闭日志记录子系统并停止所有异步线程:

    ((LifeCycle) LogManager.getContext()).stop();

(This needs to be better documented...) (这需要更好地记录...)

我已升级到log4j2-beta-9,并且工作正常。

在Web应用程序上下文中最适合我的是

org.apache.logging.log4j.LogManager.shutdown();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM