Reputation: 1983
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.
Upvotes: 0
Views: 1946
Reputation: 21
What worked best for me in a web application context was
org.apache.logging.log4j.LogManager.shutdown();
Upvotes: 0
Reputation: 36754
This will shut down the logging sub system and stop any async threads:
((LifeCycle) LogManager.getContext()).stop();
(This needs to be better documented...)
Upvotes: 1