You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@logging.apache.org by "Robin Jansohn (JIRA)" <ji...@apache.org> on 2017/04/21 11:54:04 UTC

[jira] [Commented] (LOG4J2-1098) log4j.shutdownHookEnabled=false from log4j-web ignored?

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

Robin Jansohn commented on LOG4J2-1098:
---------------------------------------

Thanks Kim, your solution/workaround is indeed working. According to the documentation (https://logging.apache.org/log4j/2.x/manual/webapp.html#Servlet-2.5) you should probably also add the filter explicitly:

{code:xml}
    <filter>
        <filter-name>log4jServletFilter</filter-name>
        <filter-class>org.apache.logging.log4j.web.Log4jServletFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>log4jServletFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
        <dispatcher>ERROR</dispatcher>
        <dispatcher>ASYNC</dispatcher><!-- Servlet 3.0 w/ disabled auto-initialization only; not supported in 2.5 -->
    </filter-mapping>
{code}

I'm additionally using the context param {{log4jConfiguration}} which leads to an unnecessary error message during startup with your workaround:
{noformat}
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'org.apache.logging.log4j.simplelog.StatusLogger.level' to TRACE to show Log4j2 internal initialization logging.
{noformat}

It first tries and fails to find the configuration via system properties and on the classpath. Only in the second step the logger context is correctly initialized with the configuration specified by the context param {{log4jConfiguration}}. This is only a minor issue as all logging messages are properly displayed.

> 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)