[ 
https://issues.apache.org/jira/browse/LOG4J2-1098?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15899623#comment-15899623
 ] 

Kim commented on LOG4J2-1098:
-----------------------------

I faced a similar problem (no logging during shutdown) with log4j 2.6.1.
I traced it down to {{Log4jServletContainerInitializer}} adding 
{{Log4jServletContextListener}} to *the end* of the application's listeners.
I had explicitly added {{Log4jServletContextListener}} *first* in {{web.xml}}, 
but this only resulted in the listener being twice in the list of listeners 
(first and last).
Because listeners are destroyed in reverse order, logging was effectively shut 
down as the first thing during shutdown.

My solution was to disable automatic initialization and specifying 
{{Log4jServletContextListener}} as the first listener:

{code:xml|title=web.xml}
    <!-- We disable log4j2 auto-initialization, because it shuts down log4j too 
early - preventing logging during other AppContextListeners' contextDestroyed() 
-->
    <context-param>
        <param-name>isLog4jAutoInitializationDisabled</param-name>
        <param-value>true</param-value>
    </context-param>

    <!-- Init log4j2 explicitly - starting first and shutting down last -->
    <listener>
        
<listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
    </listener>

    <!-- Other listeners here -->
{code}

Maybe this could be of help to someone.

> log4j.shutdownHookEnabled=false from log4j-web ignored?
> -------------------------------------------------------
>
>                 Key: LOG4J2-1098
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1098
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Web/Servlet
>    Affects Versions: 2.3
>            Reporter: Robin Jansohn
>
> In the documentation it says for the System Property 
> 'log4j.shutdownHookEnabled':
> {quote}
> Overrides the global flag for whether or not a shutdown hook should be used 
> to stop a LoggerContext. By default, this is enabled and can be disabled on a 
> per-configuration basis. When running with the log4j-web module, this is 
> automatically disabled.
> {quote}
> I included the log4j-web module into my Maven project so the shutdown hook 
> should be disabled. During initialization I can see in the debug messages 
> that this is not the case:
> {quote}
> DEBUG Starting LoggerContext\[name=31484215\] from configuration at null
> DEBUG Starting LoggerContext\[name=31484215, 
> org.apache.logging.log4j.core.LoggerContext@1836523\] with configuration 
> XmlConfiguration\[location=C:\app\apache-tomcat-8.0.24\wtpwebapps\webapp\WEB-INF\classes\log4j2.xml\]...
> DEBUG *Shutdown hook enabled. Registering a new one.*
> DEBUG Starting configuration 
> XmlConfiguration\[location=C:\app\apache-tomcat-8.0.24\wtpwebapps\webapp\WEB-INF\classes\log4j2.xml\]
> \[...\]
> {quote}
> During shutdown (more specifically the contextDestroyed method of the 
> ServletContextListener) I try to log some messages but the Logger is already 
> shut down and therefore swallows all log messages (see LOG4J2-658).
> Do I need to do something else to disable the shutdown hook?



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org

Reply via email to