Skip to content

Shutdown of Log4j2 initialized via Log4jServletContainerInitializer happens first not last #1782

Closed
@cseewald

Description

@cseewald

Description

Shutdown of Log4j2 system initialized via org.apache.logging.log4j.web.Log4jServletContainerInitializer happens first before all ServletContextListener contextDestroyed methods are called in a servlet container (tomcat).

I would expect Log4j2 to shutdown itself at the very end, so other context listeners have the change to log something during their shutdown procedure.

If I intialize/shutdown log4j2 via org.apache.logging.log4j.web.Log4jServletContextListener and put the context listener at the very top in web.xml then log4j2 properly shuts down after every other listener.

If I debug

        if (!"true".equalsIgnoreCase(servletContext.getInitParameter(
                Log4jWebSupport.IS_LOG4J_AUTO_SHUTDOWN_DISABLED))) {
            servletContext.addListener(new Log4jServletContextListener());
        }

in Log4jServletContainerInitializer, all other listener already exists in the servletContext and the Log4jServletContextListener is added to the very end, thus shutdown happens as the very first.

Configuration

Version: log4j2-web 2.20.0

Operating system: MacOS

JDK: JDK 11 Temurin

Servlet Container:: Tomcat 9.0.73

Logs

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect, unexpected, or unintended behavior of existing code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions