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

ASF subversion and git services commented on LOG4J2-1606:
---------------------------------------------------------

Commit 516756119ff74cb5b4bcbea425bf6b26ec630f63 in logging-log4j2's branch 
refs/heads/release-2.x from perry2of5
[ https://gitbox.apache.org/repos/asf?p=logging-log4j2.git;h=5167561 ]

LOG4J2-1606 LOG4J2-2624 Add flag to disable automatic log4j shutdown in 
log4j-web. (#463)

Added flag to control auto-shutdown of Log4j when
Log4jServletContainerInitializer is used for a servlet 3+ deployment.

Added "Log4jShutdownOnContextDestroyedListener", a
ServletContextListener, to shutdown log4j cleanly when
contextDestroyed is called. Assuming this ServletContextListener is
the very first listener registered in the web application's web.xml,
then log4j will be shut down after all other components are shut down.
Log4jShutdownOnContextDestroyedListener should only be used when
auto-shutdown is disabled in Log4jServletContainerInitializer.

> 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
>            Priority: Major
>
> 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
(v8.3.4#803005)

Reply via email to