Question

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? is it a bug or any configuration is explicit to kill the thread.

My sample summary 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;

import 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. Can anyone please help me.

Était-ce utile?

La solution 2

I Upgraded to log4j2-beta-9 and it works fine.

Autres conseils

This will shut down the logging sub system and stop any async threads:

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

(This needs to be better documented...)

What worked best for me in a web application context was

org.apache.logging.log4j.LogManager.shutdown();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top