ppkarwasz commented on issue #1782: URL: https://github.com/apache/logging-log4j2/issues/1782#issuecomment-1712727768
@cseewald, Thank you for noticing this issue. Unfortunately the Servlet API treats listeners as second-class citizens compared to servlets and filters: there is no way to give them a name, overwrite their definition or even check if such a listener is defined. [Section 8.2.3](https://jakarta.ee/specifications/servlet/6.0/jakarta-servlet-spec-6.0#Assembling_the_descriptor) gives some rules on how listeners are ordered and gives a warning: > If the order in which the listeners, servlets, filters are invoked is important to an application then a deployment descriptor must be used. Unless I am mistaken the order of the listeners is: 1. those explicitly defined in `web.xml`, 2. those annotated with `@WebListener` (in a random order) unless `metadata-complete` is set, 3. those explicitly defined in `web-fragment.xml` unless `metadata-complete` is set, 4. those added by a `ServletContainerInitializer`. so there is no way for Log4j to put their listener first. The best we can do is: - document this problem and ask the user to explicitly add `org.apache.logging.log4j.web.Log4jServletContextListener` at the top of their `web.xml` file, - count the number of `Log4jServletContextListener` instances (there will be more than one, since they don't have a name), in a servlet container, so that only the last call to `contextDestroyed` shuts down the logger context. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
