You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Schindler, René" <re...@salt-solutions.de.INVALID> on 2022/06/14 07:40:05 UTC

RE: [External] Re: Shutting down Log4j2 in a JavaEE environment that does not include servlets

Hi Piotr,

we are currently running a Webshpere traditional application server and are planning to move to openliberty in the foreseeable future.

The flags you gave me helped. I could identify two culprits. One is a LoggerInterceptor, which is still running and requesting loggers when the app is shutting down (it is intercepting @PreDestroy).
The other one is a Log4jBridgeHandler (runs in another module), which wants to close itself during shutdown.

If one of these two is called after LogManager.shutdown(), then the logging infrastructure restarts.
So I need to make sure LogManager.shutdown() is the last in line to be called or to prevent it from starting up again.
Any idea how I might do that?

Rene

-----Original Message-----
From: Piotr P. Karwasz <pi...@gmail.com>
Sent: Montag, 13. Juni 2022 10:15
To: Log4J Users List <lo...@logging.apache.org>
Subject: [External] Re: Shutting down Log4j2 in a JavaEE environment that does not include servlets

This message is from an EXTERNAL SENDER - be CAUTIOUS, particularly with links and attachments.

Hi René,

On Fri, 10 Jun 2022 at 16:36, Schindler, René <re...@salt-solutions.de.invalid> 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

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


________________________________

This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited.