Skip to content

Commit

Permalink
Merge pull request #162 from jamezp/LOGMGR-187
Browse files Browse the repository at this point in the history
[LOGMGR-187] The ClassLoaderLogContextSelector should keep searching …
  • Loading branch information
jamezp authored Jan 19, 2018
2 parents ce7bad5 + 2014d5d commit 72ac257
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.Permission;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
Expand Down Expand Up @@ -89,8 +90,14 @@ public ClassLoaderLogContextSelector(final boolean checkParentClassLoaders) {

private final PrivilegedAction<LogContext> logContextAction = new PrivilegedAction<LogContext>() {
public LogContext run() {
final Class<?> callingClass = JDKSpecific.findCallingClass(logApiClassLoaders);
return callingClass == null ? defaultSelector.getLogContext() : check(callingClass.getClassLoader());
final Collection<Class<?>> callingClasses = JDKSpecific.findCallingClasses(logApiClassLoaders);
for (Class<?> caller : callingClasses) {
final LogContext result = check(caller.getClassLoader());
if (result != null) {
return result;
}
}
return defaultSelector.getLogContext();
}

private LogContext check(final ClassLoader classLoader) {
Expand All @@ -102,7 +109,7 @@ private LogContext check(final ClassLoader classLoader) {
if (parent != null && checkParentClassLoaders && ! logApiClassLoaders.contains(parent)) {
return check(parent);
}
return defaultSelector.getLogContext();
return null;
}
};

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/jboss/logmanager/JDKSpecific.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.jboss.modules.Module;
Expand Down Expand Up @@ -65,6 +68,17 @@ static Class<?> findCallingClass(Set<ClassLoader> rejectClassLoaders) {
return null;
}

static Collection<Class<?>> findCallingClasses(Set<ClassLoader> rejectClassLoaders) {
final Collection<Class<?>> result = new LinkedHashSet<>();
for (Class<?> caller : GATEWAY.getClassContext()) {
final ClassLoader classLoader = caller.getClassLoader();
if (classLoader != null && ! rejectClassLoaders.contains(classLoader)) {
result.add(caller);
}
}
return result;
}

static void calculateCaller(ExtLogRecord logRecord) {
final String loggerClassName = logRecord.getLoggerClassName();
final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
Expand Down

0 comments on commit 72ac257

Please sign in to comment.