I know it is probably out of date, but I felt your question, and I was in the same situation. Therefore, for interested people, I use this piece of code to stop the program completion code:
final LoggerContextFactory factory = LogManager.getFactory(); if (factory instanceof Log4jContextFactory) { LOG.info("register shutdown hook"); Log4jContextFactory contextFactory = (Log4jContextFactory) factory; ((DefaultShutdownCallbackRegistry) contextFactory.getShutdownCallbackRegistry()).stop(); }
and in my own stop cache
LogManager.shutdown();
log4j2: 2.8.2 (but should be available since 2.6)
Laurent P.
source share