@@ -133,8 +133,7 @@ public synchronized boolean addLogger(final Logger logger) {
133133
134134 final String loggerName = logger .getName ();
135135
136- ClassLoader classLoader =
137- Thread .currentThread ().getContextClassLoader ();
136+ ClassLoader classLoader = getClassLoader ();
138137 ClassLoaderLogInfo info = getClassLoaderInfo (classLoader );
139138 if (info .loggers .containsKey (loggerName )) {
140139 return false ;
@@ -224,8 +223,7 @@ public synchronized boolean addLogger(final Logger logger) {
224223 */
225224 @ Override
226225 public synchronized Logger getLogger (final String name ) {
227- ClassLoader classLoader = Thread .currentThread ()
228- .getContextClassLoader ();
226+ ClassLoader classLoader = getClassLoader ();
229227 return getClassLoaderInfo (classLoader ).loggers .get (name );
230228 }
231229
@@ -236,8 +234,7 @@ public synchronized Logger getLogger(final String name) {
236234 */
237235 @ Override
238236 public synchronized Enumeration <String > getLoggerNames () {
239- ClassLoader classLoader = Thread .currentThread ()
240- .getContextClassLoader ();
237+ ClassLoader classLoader = getClassLoader ();
241238 return Collections .enumeration (getClassLoaderInfo (classLoader ).loggers .keySet ());
242239 }
243240
@@ -280,7 +277,7 @@ public String getProperty(String name) {
280277
281278
282279 private synchronized String findProperty (String name ) {
283- ClassLoader classLoader = Thread . currentThread (). getContextClassLoader ();
280+ ClassLoader classLoader = getClassLoader ();
284281 ClassLoaderLogInfo info = getClassLoaderInfo (classLoader );
285282 String result = info .props .getProperty (name );
286283 // If the property was not found, and the current classloader had no
@@ -313,7 +310,7 @@ public void readConfiguration()
313310
314311 checkAccess ();
315312
316- readConfiguration (Thread . currentThread (). getContextClassLoader ());
313+ readConfiguration (getClassLoader ());
317314
318315 }
319316
@@ -324,7 +321,7 @@ public void readConfiguration(InputStream is)
324321 checkAccess ();
325322 reset ();
326323
327- readConfiguration (is , Thread . currentThread (). getContextClassLoader ());
324+ readConfiguration (is , getClassLoader ());
328325
329326 }
330327
@@ -337,7 +334,7 @@ public void reset() throws SecurityException {
337334 // because we have our own shutdown hook
338335 return ;
339336 }
340- ClassLoader classLoader = thread . getContextClassLoader ();
337+ ClassLoader classLoader = getClassLoader ();
341338 ClassLoaderLogInfo clLogInfo = getClassLoaderInfo (classLoader );
342339 resetLoggers (clLogInfo );
343340 // Do not call super.reset(). It should be a NO-OP as all loggers should
@@ -389,16 +386,17 @@ private void resetLoggers(ClassLoaderLogInfo clLogInfo) {
389386
390387 /**
391388 * Retrieve the configuration associated with the specified classloader. If
392- * it does not exist, it will be created.
389+ * it does not exist, it will be created. If no class loader is specified,
390+ * the class loader used to load this class is used.
393391 *
394- * @param classLoader The classloader for which we will retrieve or build the
395- * configuration
392+ * @param classLoader The class loader for which we will retrieve or build
393+ * the configuration
396394 * @return the log configuration
397395 */
398396 protected synchronized ClassLoaderLogInfo getClassLoaderInfo (ClassLoader classLoader ) {
399397
400398 if (classLoader == null ) {
401- classLoader = ClassLoader . getSystemClassLoader ();
399+ classLoader = this . getClass (). getClassLoader ();
402400 }
403401 ClassLoaderLogInfo info = classLoaderLoggers .get (classLoader );
404402 if (info == null ) {
@@ -652,7 +650,7 @@ protected String replace(String str) {
652650
653651
654652 private String replaceWebApplicationProperties (String propName ) {
655- ClassLoader cl = Thread . currentThread (). getContextClassLoader ();
653+ ClassLoader cl = getClassLoader ();
656654 if (cl instanceof WebappProperties ) {
657655 WebappProperties wProps = (WebappProperties ) cl ;
658656 if ("classloader.webappName" .equals (propName )) {
@@ -670,9 +668,28 @@ private String replaceWebApplicationProperties(String propName) {
670668 }
671669
672670
673- // ---------------------------------------------------- LogNode Inner Class
671+ /**
672+ * Obtain the class loader to use to lookup loggers, obtain configuration
673+ * etc. The search order is:
674+ * <ol>
675+ * <li>Thread.currentThread().getContextClassLoader()</li>
676+ * <li>The class laoder of this class</li>
677+ * </ol>
678+ *
679+ * @return The class loader to use to lookup loggers, obtain configuration
680+ * etc.
681+ */
682+ static ClassLoader getClassLoader () {
683+ ClassLoader result = Thread .currentThread ().getContextClassLoader ();
684+ if (result == null ) {
685+ result = ClassLoaderLogManager .class .getClassLoader ();
686+ }
687+ return result ;
688+ }
674689
675690
691+ // ---------------------------------------------------- LogNode Inner Class
692+
676693 protected static final class LogNode {
677694 Logger logger ;
678695
0 commit comments