[ https://issues.apache.org/jira/browse/LOG4J2-359?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13755633#comment-13755633 ]
Ralph Goers commented on LOG4J2-359: ------------------------------------ Sorry for editing the comments but I keep finding typos or need to add more detail. For example, when I said annotation in my last comment it really should have been "interface" as that is what @HandleTypes expects. First, I hate relying on behaviors that can change from release to release rather than something in the spec, so I applaude your effort to get that corrected. I disagree that it is invalid to define Log4j's listener in web.xml. It may be undesirable but it is not invalid. Again, logging a warning that says that it might not work correctly is preferable to aborting the application. Shouldn't it behave essentially as it does in 2.5? You are saying we can't reasonably expect users to create jars that they place in WEB-INF/lib? You can't be serious. I do that all the time. I don't think it is any more unreasonable to expect an application to provide an initializer for Log4j than it is for Spring, although it will occur less frequently. The problem with locating the "proper" configuration file is that you don't know whether it is json, xml or something else so you essentially have to run through all the same logic that ConfigurationFactory does. What if the user wants to place the Log4j jar in the container but then provide a custom configuration factory in one of the web apps? Right now we don't support that but it wouldn't be a big deal to add a new Configurator method that accepts a ConfigurationFactory as an argument. The user would then want to set this up in their own Log4jInitializer by doing: {code} public void onStartup(ServletContext servletContext) { ConfigurationFactory factory = new MyConfigurationFactory(servletContext.getInitParam("MyInitData")); LoggerContext context = Configurator.initialize(servletContext.getServletContextName(), servletContext.getClassLoader(), factory, servletContext); servletContext.setAttribute(org.apache.logging.log4j.core.helpers.Constants.LOG4J_SERVLET_CONTEXT, context); } {code} I strongly believe that if we are going to have a ServletContainerInitializer at all that it must support this kind of flexibility. In addition, we also need to allow the user to do the same sort of thing from a Spring WebApplicationInitializer. Notice that this could be handled by checking whether the ServletContext attribute for the LoggerContext has been set. > 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