- java.lang.Object
-
- org.jboss.logmanager.CallerClassLoaderLogContextSelector
-
- All Implemented Interfaces:
LogContextSelector
public final class CallerClassLoaderLogContextSelector extends Object implements LogContextSelector
A log context selector which chooses a log context based on the caller's classloader. The first caller that is not a log API or does not have anullclassloader will be the class loader used.
-
-
Constructor Summary
Constructors Constructor Description CallerClassLoaderLogContextSelector()Construct a new instance.CallerClassLoaderLogContextSelector(boolean checkParentClassLoaders)Construct a new instance.CallerClassLoaderLogContextSelector(LogContextSelector defaultSelector)Construct a new instance.CallerClassLoaderLogContextSelector(LogContextSelector defaultSelector, boolean checkParentClassLoaders)Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddLogApiClassLoader(ClassLoader apiClassLoader)Register a class loader which is a known log API, and thus should be skipped over when searching for the log context to use for the caller class.LogContextgetLogContext()Get the current log context.voidregisterLogContext(ClassLoader classLoader, LogContext logContext)Register a class loader with a log context.booleanremoveLogApiClassLoader(ClassLoader apiClassLoader)Remove a class loader from the known log APIs set.booleanunregisterLogContext(ClassLoader classLoader, LogContext logContext)Unregister a class loader/log context association.
-
-
-
Constructor Detail
-
CallerClassLoaderLogContextSelector
public CallerClassLoaderLogContextSelector(LogContextSelector defaultSelector)
Construct a new instance. If no matching log context is found, the provided default selector is consulted.- Parameters:
defaultSelector- the selector to consult if no matching log context is found
-
CallerClassLoaderLogContextSelector
public CallerClassLoaderLogContextSelector(LogContextSelector defaultSelector, boolean checkParentClassLoaders)
Construct a new instance. If no matching log context is found, the provided default selector is consulted.If the
checkParentClassLoadersis set totruethis selector recursively searches the class loader parents until a match is found or anullparent is found.- Parameters:
defaultSelector- the selector to consult if no matching log context is foundcheckParentClassLoaders-trueif thelog contextcould not found for the class loader and theparent class loadershould be checked
-
CallerClassLoaderLogContextSelector
public CallerClassLoaderLogContextSelector()
Construct a new instance. If no matching log context is found, the system context is used.
-
CallerClassLoaderLogContextSelector
public CallerClassLoaderLogContextSelector(boolean checkParentClassLoaders)
Construct a new instance. If no matching log context is found, the system context is used.If the
checkParentClassLoadersis set totruethis selector recursively searches the class loader parents until a match is found or anullparent is found.- Parameters:
checkParentClassLoaders-trueif thelog contextcould not found for the class loader and theparent class loadershould be checked
-
-
Method Detail
-
getLogContext
public LogContext getLogContext()
Get the current log context. This instance will consult the call stack to see if the first callers classloader is associated with a log context. The first caller is determined by the first class loader that is not registered as a log API.- Specified by:
getLogContextin interfaceLogContextSelector- Returns:
- the current log context
-
addLogApiClassLoader
public boolean addLogApiClassLoader(ClassLoader apiClassLoader)
Register a class loader which is a known log API, and thus should be skipped over when searching for the log context to use for the caller class.- Parameters:
apiClassLoader- the API class loader- Returns:
trueif this class loader was previously unknown, orfalseif it was already registered
-
removeLogApiClassLoader
public boolean removeLogApiClassLoader(ClassLoader apiClassLoader)
Remove a class loader from the known log APIs set.- Parameters:
apiClassLoader- the API class loader- Returns:
trueif the class loader was removed, orfalseif it was not known to this selector
-
registerLogContext
public void registerLogContext(ClassLoader classLoader, LogContext logContext) throws IllegalArgumentException
Register a class loader with a log context. This method requires theregisterLogContextRuntimePermission.- Parameters:
classLoader- the classloaderlogContext- the log context- Throws:
IllegalArgumentException- if the classloader is already associated with a log context
-
unregisterLogContext
public boolean unregisterLogContext(ClassLoader classLoader, LogContext logContext)
Unregister a class loader/log context association. This method requires theunregisterLogContextRuntimePermission.- Parameters:
classLoader- the classloaderlogContext- the log context- Returns:
trueif the association exists and was removed,falseotherwise
-
-