Description

We are experiencing difficulty getting web applications deployed under Tomcat 6.0.x to honor per-app Log4J2 configuration, when Tomcat itself has been modified to also use Log4J2.

I will attach a modified Tomcat archive with the following steps applied:
1. Download and decompress Tomcat 6.0.36
2. Follow steps #3 and #4 at https://tomcat.apache.org/tomcat-6.0-doc/logging.html#Using_Log4j , but instead of using Log4J 1.x, use Log4J 2.0-beta4 core, api, and log4j-1.2 jars.
3. Deploy a web application to Tomcat which includes Log4J 2.0-beta4 .jar files, and includes the following in web.xml:
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>$

{log4j.app.configurationFile}

</param-value>
</context-param>

<listener>
<listener-class>org.apache.logging.log4j.core.web.Log4jContextListener</listener-class>
</listener>
4. Create two Log4J2 configuration files, one for Tomcat and one for the web app. They should use different PatternLayouts so output can be distinguished from each other.
5. Launch Tomcat, passing the following environment variable:
CATALINA_OPTS="-Dlog4j.app.configurationFile=/path/to/log4j2-webapp.xml -Dlog4j.configurationFile=/path/to/log4j2-tomcat.xml"
6. Force the web app to generate a log message.
7. View Tomcat's catalina.out file, and observe messages from the web app are output with Tomcat's configured PatternLayout.

The final message is from the web app, and should be prefixed with "APP" instead of "TOMCAT".

We've run this process in a debugger, and can observe Log4J2 being initialized both by Tomcat and the web app, with no errors. Still, for some reason the web application is using Tomcat's configuration instead of the supplied app-specific config file.

A mailing list suggestion was to only include Log4J2 core .jar in Tomcat (not in the web app). However, at startup, we get the "SimpleLogger" error message from the web app, as the Tomcat's version of the Log4J2 core .jar is hidden from the web app's classloader.

We're at a loss. Due to Tomcat's architecture, we seemingly must include Log4J2 core in both Tomcat and the web app. In a debugger, we can see both configuration files being loaded. However, when the application sends log messages, they end up using Tomcat's configuration.