Programmatically disable the stop hook in log4j 2

You can disable disconnect hooks in log4j2 through the configuration:

<Configuration shutdownHook="disable"> 

Is it possible to do this programmatically?

+7
log4j2 shutdown-hook
source share
1 answer

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)

0
source share

All Articles