[ https://issues.apache.org/jira/browse/LOG4J2-359?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13755572#comment-13755572 ]
Nick Williams commented on LOG4J2-359: -------------------------------------- 1. No, it would not be valid to specify the listener in {{web.xml}} in a Servlet 3.0 application (the container doesn't matter, only the effective application version). 2. It would also be completely unnecessary for them to manually specify the listener in {{web.xml}} in a Servlet 3.0 application. Doing so would not provide them any benefit, as they can customize the behavior using context parameters without manually specifying the listener. 3. If they _did_ manually specify the listener in {{web.xml}}, it would not have any negative impact on the application working correctly, because the second call to initialize the {{Log4jWebInitializer}} is ignored. The problem present in this bug was specifically that the _filter_ was being added twice (which might not be immediately clear since the errors were all in the listener and the initializer). It's important for the filter to be added so that it executes before any filters defined in {{web.xml}}, so adding it in the initializer is the safest route. In Servlet 2.5 applications the filter won't be added in the initializer (and neither will the listener). In Servlet 3.0+ applications, Log4j makes in clear with a specific error message that the user must not specify the filter in {{web.xml}}. 4. The initializer _must_ run automatically in a {{ServletContainerInitializer}}. This is not an option. The reason for this is that other {{ServletContainerInitializer}} implementations, such as the one provided by Spring Framework, may trigger behavior that causes logging to take place. If this happens before the initializer runs, all bets are off. Log4j will not start up correctly and will cause errors on shutdown. > Log4jServletContextListener does not work on Weblogic 12.1.1 (12c) with > web-app version "2.5" > --------------------------------------------------------------------------------------------- > > Key: LOG4J2-359 > URL: https://issues.apache.org/jira/browse/LOG4J2-359 > Project: Log4j 2 > Issue Type: Bug > Affects Versions: 2.0-beta8 > Reporter: Abhinav Shah > Assignee: Nick Williams > Fix For: 2.0-beta9 > > Attachments: LOG4J2-359.patch, Log4jServletContainerInitializer.java, > Log4jServletContainerInitializerTest.java > > > I have Weblogic 12c running. My web-app is version "2.5". > Following is a snippet from my web.xml > {code:xml} > <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns="http://java.sun.com/xml/ns/javaee" > xsi:schemaLocation="http://java.sun.com/xml/ns/javaee > http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" > id="WebApp_ID" version="2.5"> > <display-name>pec-service</display-name> > <context-param> > <param-name>log4jConfiguration</param-name> > <param-value>file:/C:/log4j/dev.log4j.xml</param-value> > </context-param> > <listener> > > <listener-class>org.apache.logging.log4j.core.web.Log4jServletContextListener</listener-class> > > </listener> > <filter> > <filter-name>log4jServletFilter</filter-name> > > <filter-class>org.apache.logging.log4j.core.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> > </filter-mapping> > > </web-app> > {code} > However, on my server startup I am getting the following error - > {code} > <Aug 16, 2013 3:12:32 PM PDT> <Warning> <HTTP> <BEA-101162> <User defined > listener org.apache.logging.log4j.core.web.Log4jServletContextListener > failed: java.lang.IllegalStateException: Context destroyed before it was > initialized.. > java.lang.IllegalStateException: Context destroyed before it was initialized. > at > org.apache.logging.log4j.core.web.Log4jServletContextListener.contextDestroyed(Log4jServletContextListener.java:51) > at > weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:583) > at > weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) > at > weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) > at > weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57) > Truncated. see log file for complete stacktrace > > > <Aug 16, 2013 3:12:32 PM PDT> <Error> <Deployer> <BEA-149265> <Failure > occurred in the execution of deployment request with ID "1376691143681" for > task "2". Error is: "weblogic.application.ModuleException" > weblogic.application.ModuleException > at > weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1708) > at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:781) > at > weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:213) > at > weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:208) > at > weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:35) > Truncated. see log file for complete stacktrace > Caused By: java.lang.NullPointerException > at > org.apache.logging.log4j.core.web.Log4jServletContainerInitializer.onStartup(Log4jServletContainerInitializer.java:44) > at > weblogic.servlet.internal.WebAppServletContext.initContainerInitializer(WebAppServletContext.java:1271) > at > weblogic.servlet.internal.WebAppServletContext.initContainerInitializers(WebAppServletContext.java:1229) > at > weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1726) > at > weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:2740) > Truncated. see log file for complete stacktrace > > > <Aug 16, 2013 3:12:32 PM PDT> <Error> <Deployer> <BEA-149202> <Encountered an > exception while attempting to commit the 7 task for the application > "_auto_generated_ear_".> > <Aug 16, 2013 3:12:32 PM PDT> <Warning> <Deployer> <BEA-149004> <Failures > were detected while initiating start task for application > "_auto_generated_ear_".> > <Aug 16, 2013 3:12:32 PM PDT> <Warning> <Deployer> <BEA-149078> <Stack trace > for message 149004 > weblogic.application.ModuleException > at > weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1708) > at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:781) > at > weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:213) > at > weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:208) > at > weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:35) > Truncated. see log file for complete stacktrace > Caused By: java.lang.NullPointerException > at > org.apache.logging.log4j.core.web.Log4jServletContainerInitializer.onStartup(Log4jServletContainerInitializer.java:44) > at > weblogic.servlet.internal.WebAppServletContext.initContainerInitializer(WebAppServletContext.java:1271) > at > weblogic.servlet.internal.WebAppServletContext.initContainerInitializers(WebAppServletContext.java:1229) > at > weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1726) > at > weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:2740) > Truncated. see log file for complete stacktrace > {code} > If I remove the listener & the filter, it works fine. > {color:red} > I did some research and found that even though the web-app is version "2.5", > the {code}Log4jServletContainerInitializer{code} is getting invoked. > {color} -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-dev-h...@logging.apache.org