Re: Shutting down Log4j2 in a JavaEE environment that does not include servlets
"Piotr P. Karwasz" <[email protected]> Mon, 13 Jun 2022 10:15:25 +0200
| Newsgroups | gmane.comp.jakarta.log4j.user |
|---|---|
| Message-ID | <CAFmygFbE6WqN2zxAKety56+zreV629syaXThcrxgHH8CMByi3g@mail.gmail.com> |
Hi René, On Fri, 10 Jun 2022 at 16:36, Schindler, René <[email protected]> wrote: > Therefore we came up with this workaround: > > @PreDestroy > public static void shutDown() { > org.apache.logging.log4j.LogManager.shutdown(); > > Configurator.reconfigure(new NullConfiguration()); > Server.unregisterMBeans(); > } > > It prevents the instantiation of the appenders and async loggers and replacing the current config with a NullConfiguration. > The restart still takes place, but it does not prevent the undeplyoment any more (when getting rid of existing MBeans). > > Is there a more elegant solution, maybe getting rid of the restart in the first place? Can you add more details about your deployment? What application server are you using? To find out, which component reinitializes Log4j2, you can run the server with: -Dlog4j2.debug=true -Dlog4j2.loggerContextStacktraceOnStart=true which will log a stack trace of the call that initialized the logger context. Piotr