You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@logging.apache.org by Remko Popma <re...@gmail.com> on 2017/11/23 22:38:00 UTC

Re: [jira] [Commented] (LOG4J2-1606) log4j-web deinitalizes the Logger too early if listeners defined in web.xml use it

Guys, if any of your findings should be reflected in the Log4j2
documentation for web applications, please let us know (I'm not following
this discussion in enough detail to judge whether the Log4j2 docs need
adjustment).

Documentation patches are always welcome!

On Thu, Nov 23, 2017 at 10:54 PM, Pavel Erofeev (JIRA) <ji...@apache.org>
wrote:

>
>     [ https://issues.apache.org/jira/browse/LOG4J2-1606?page=
> com.atlassian.jira.plugin.system.issuetabpanels:comment-
> tabpanel&focusedCommentId=16264359#comment-16264359 ]
>
> Pavel Erofeev commented on LOG4J2-1606:
> ---------------------------------------
>
> Thanks a lot [~lukedirtwalker] and [~rturner@e-djuster.com]
> After trying different workarounds I found the one which works fine for us:
> * I keep log4j-web on the classpath
> * In web.xml I disable auto initialization with context param {{
> isLog4jAutoInitializationDisabled}}
> * I include {{Log4jServletContextListener}} as the first listener in
> web.xml - it guarantees the right order of initialization / shutdown
> * Inside all other context listeners, I don't create loggers before
> contextInitialized is called
>
> > log4j-web deinitalizes the Logger too early if listeners defined in
> web.xml use it
> > ------------------------------------------------------------
> -----------------------
> >
> >                 Key: LOG4J2-1606
> >                 URL: https://issues.apache.org/jira/browse/LOG4J2-1606
> >             Project: Log4j 2
> >          Issue Type: Bug
> >          Components: Web/Servlet
> >    Affects Versions: 2.6.2
> >         Environment: Java8, Linux/Mac, Tomcat
> >            Reporter: Lukas Vogel
> >
> > We use log4j in a Apache Tomcat environment.
> > In the web.xml file we define a custom ServerStartup listener that
> initializes the DB etc and logs both in contextInitialized and
> contextDestroyed.
> > If we use the log4j-web package the class Log4jServletContainerInitializer
> initializes the logger and adds a Log4jServletContextListener to the
> ServletContext. Since this listener is added after our listener the method
> Log4jServletContextListener#contextDestroyed is called before our
> listener's contextDestroyed method. Thus the Logger is de-initialized too
> early.
> > We could disable auto initialization and initialize the logger ourselves
> but then doing it in the listener is too late since the
> WebService-framework (Metro glassfish) initializes the webservice endpoints
> before the listener. Since we use static logger variables in those
> webservice classes this would trigger the message "StatusLogger no log4j
> configuration found..."  because the logger was not yet initialized.
> > One possible patch we see is that we make an option to manually add the
> Log4jServletContextListener:
> > In Log4jServletContainerInitializer we would put an "if (! Manually
> added)" around the  call "servletContext.addListener(new
> Log4jServletContextListener());" and then we could manually add it to the
> listeners in web.xml
> > If you have any other suggestions I would be glad to hear them.
>
>
>
> --
> This message was sent by Atlassian JIRA
> (v6.4.14#64029)
>