Bill Okara created LOG4J2-2065:
----------------------------------
Summary: Wrong classLoader used to create loggerContext for
container shared lib
Key: LOG4J2-2065
URL: https://issues.apache.org/jira/browse/LOG4J2-2065
Project: Log4j 2
Issue Type: Bug
Components: Core
Affects Versions: 2.9.1
Reporter: Bill Okara
Tested with log4j2 v2.9.1, tomcat 7 latest on linux
When multiple webapps, say webapp1 and webapp2, use a shared apache lib (say
commonLib, which also uses log4j logging) that deployed as jndi resource in
tomcat (thus was put in tomcat/lib) with the following deployment structure:
tomcat/lib:
- log4j-core.jar, log4j-api.jar
- commonLib.jar
- log4j2.xml
webapp1 and webapp2, in /WEB-INF:
- classes/log4j2.xml
- lib/log4j2-web.jar
When loading, the ClassLoaderContextSelector correctly uses the
webappClassloader to load the log4j config for webapp1 and webapp2. But for the
commonLib loggerContext, depending on which webapp got loaded first, the
commonLib loggerContext will either be using
webapp1/WEB-INF/classes/log4j2.xml
or
webapp2/WEB-INF/classes/log4j2.xml
instead of the log4j2.xml provided in tomcat/lib.
Followings are the debug log output for reference:
{{
DEBUG StatusLogger Log4jServletContainerInitializer starting up Log4j in
Servlet 3.0+ environment.
DEBUG StatusLogger Using ShutdownCallbackRegistry class
org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry
DEBUG StatusLogger Using the servlet context name "webapp1".
DEBUG StatusLogger getConfigURI found [classpath:log4j2.xml] in servletContext
at [classpath:log4j2.xml]
DEBUG StatusLogger Took 0.119686 seconds to load 204 plugins from
WebappClassLoader
context: /webapp1
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
java.net.URLClassLoader@6dde5c8c
..
DEBUG StatusLogger Starting LoggerContext[name=webapp1] from configuration at
classpath:log4j2.xml
..
// then after initialized some of the code that referenced the commonLib classes
DEBUG StatusLogger Starting LoggerContext[name=6dde5c8c,
org.apache.logging.log4j.core.LoggerContext@3240b374]...
DEBUG StatusLogger Reconfiguration started for context[name=6dde5c8c] at URI
null (org.apache.logging.log4j.core.LoggerContext@3240b374) with optional
ClassLoader: null
DEBUG StatusLogger Using configurationFactory
org.apache.logging.log4j.core.config.ConfigurationFactory$Factory@5b34ed62
TRACE StatusLogger Trying to find [log4j2-test6dde5c8c.properties] using
context class loader WebappClassLoader
context: /webapp1
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
java.net.URLClassLoader@6dde5c8c
..
TRACE StatusLogger Trying to find [log4j2.jsn] using
ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2.xml] using context class loader
WebappClassLoader
context: /webapp1
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
java.net.URLClassLoader@6dde5c8c
}}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)