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

Piotr Karwasz commented on LOG4J2-3541:
---------------------------------------

Hi [~davehawkins],

Your hypothesis is correct: many Log4j2 components in the 2.x series, including 
{{{}ContextDataProviders{}}}, have a static scope and are the same for all 
logger contexts. This is unlikely to change.

In version 3.x there will be a proper dependency injection framework and all 
those components should migrate to a {{LoggerContext}} scope.

In the meantime you can work around this limitation by:
 * having a copy of `log4j-api` and `log4j-core` in each application,
 * using the standard Tomcat's {{{}ClassLoaderLogManager{}}},
 * adding a {{WEB-INF/logging.properties}} to each application that configures 
a single {{Log4jBridgeHandler}} to forward JUL messages to the appropriate 
Log4j2 logger context.

> ThreadContextDataInjector Uses Incorrect Providers Under Tomcat
> ---------------------------------------------------------------
>
>                 Key: LOG4J2-3541
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3541
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core, Web/Servlet
>    Affects Versions: 2.17.1
>         Environment: Tomcat 9.0.58 with the following jars in 
> ${CATALINA_HOME}/lib:
> log4j-api-2.17.1.jar
> log4j-core-2.17.1.jar
> log4j-jul-2.17.1.jar
> JUL LogManager is org.apache.logging.log4j.jul.LogManager
>            Reporter: Dave Hawkins
>            Priority: Major
>
> We are using Log4j with tomcat by including it in the boot classpath and 
> using Log4jServletContextListener in the web.xml. We are also using the log4j 
> JUL LogManager. Web application ContextDataProviders are not being loaded 
> correctly.
> I think this is because ThreadContextDataInjector::getServiceProviders is 
> sensitive to the web application classpath, but the class, which is shared 
> between the web applications and tomcat, statically caches the result. The 
> providers list for tomcat is initialized first and is thus incorrectly used 
> for the web applications.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to