The ClassLoaderContextSelector#locateContext currently implements the following logic:
|
if (ref == null) { |
|
if (configLocation == null) { |
|
ClassLoader parent = loader.getParent(); |
|
while (parent != null) { |
|
|
|
ref = CONTEXT_MAP.get(toContextMapKey(parent)); |
|
if (ref != null) { |
|
final WeakReference<LoggerContext> r = ref.get(); |
|
final LoggerContext ctx = r.get(); |
|
if (ctx != null) { |
|
return ctx; |
|
} |
|
} |
|
parent = parent.getParent(); |
|
/* In Tomcat 6 the parent of the JSP classloader is the webapp classloader which would be |
|
configured by the WebAppContextListener. The WebAppClassLoader is also the ThreadContextClassLoader. |
|
In JBoss 5 the parent of the JSP ClassLoader is the WebAppClassLoader which is also the |
|
ThreadContextClassLoader. However, the parent of the WebAppClassLoader is the ClassLoader |
|
that is configured by the WebAppContextListener. |
|
|
|
ClassLoader threadLoader = null; |
|
try { |
|
threadLoader = Thread.currentThread().getContextClassLoader(); |
|
} catch (Exception ex) { |
|
// Ignore SecurityException |
|
} |
|
if (threadLoader != null && threadLoader == parent) { |
|
break; |
|
} else { |
|
parent = parent.getParent(); |
|
} */ |
|
} |
|
} |
If the initial ContextSelector#getContext call does not provide a configLocation parameter and there is already a logger context associated to an ancestor of the loader classloader, no new context is created and the logger context of the ancestor is returned.
While this might be a feature to minimize the number of logger contexts, IMHO it should be optional and the default behavior should be to create a different logger context per classloader.
This behavior causes #1430 and the problems in #2311.
The
ClassLoaderContextSelector#locateContextcurrently implements the following logic:logging-log4j2/log4j-core/src/main/java/org/apache/logging/log4j/core/selector/ClassLoaderContextSelector.java
Lines 189 to 221 in f05864d
If the initial
ContextSelector#getContextcall does not provide aconfigLocationparameter and there is already a logger context associated to an ancestor of theloaderclassloader, no new context is created and the logger context of the ancestor is returned.While this might be a feature to minimize the number of logger contexts, IMHO it should be optional and the default behavior should be to create a different logger context per classloader.
This behavior causes #1430 and the problems in #2311.