Package org.jboss.logmanager
Class ClassLoaderLogContextSelector
- java.lang.Object
-
- org.jboss.logmanager.ClassLoaderLogContextSelector
-
- All Implemented Interfaces:
LogContextSelector
public final class ClassLoaderLogContextSelector extends Object implements LogContextSelector
A log context selector which chooses a log context based on the caller's classloader.
-
-
Constructor Summary
Constructors Constructor Description ClassLoaderLogContextSelector()
Construct a new instance.ClassLoaderLogContextSelector(boolean checkParentClassLoaders)
Construct a new instance.ClassLoaderLogContextSelector(LogContextSelector defaultSelector)
Construct a new instance.ClassLoaderLogContextSelector(LogContextSelector defaultSelector, boolean checkParentClassLoaders)
Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.LogContext
getLogContext()
Get the current log context.void
registerLogContext(ClassLoader classLoader, LogContext logContext)
Register a class loader with a log context.boolean
removeLogApiClassLoader(ClassLoader apiClassLoader)
Remove a class loader from the known log APIs set.boolean
unregisterLogContext(ClassLoader classLoader, LogContext logContext)
Unregister a class loader/log context association.
-
-
-
Constructor Detail
-
ClassLoaderLogContextSelector
public ClassLoaderLogContextSelector(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
-
ClassLoaderLogContextSelector
public ClassLoaderLogContextSelector(LogContextSelector defaultSelector, boolean checkParentClassLoaders)
Construct a new instance. If no matching log context is found, the provided default selector is consulted. If thecheckParentClassLoaders
is set totrue
this selector recursively searches the class loader parents until a match is found or anull
parent is found.- Parameters:
defaultSelector
- the selector to consult if no matching log context is foundcheckParentClassLoaders
-true
if thelog context
could not found for the class loader and theparent class loader
should be checked
-
ClassLoaderLogContextSelector
public ClassLoaderLogContextSelector()
Construct a new instance. If no matching log context is found, the system context is used.
-
ClassLoaderLogContextSelector
public ClassLoaderLogContextSelector(boolean checkParentClassLoaders)
Construct a new instance. If no matching log context is found, the system context is used. If thecheckParentClassLoaders
is set totrue
this selector recursively searches the class loader parents until a match is found or anull
parent is found.- Parameters:
checkParentClassLoaders
-true
if thelog context
could not found for the class loader and theparent class loader
should be checked
-
-
Method Detail
-
getLogContext
public LogContext getLogContext()
Get the current log context. This instance will consult the call stack to see if any calling classloader is associated with any log context.- Specified by:
getLogContext
in 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:
true
if this class loader was previously unknown, orfalse
if 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:
true
if the class loader was removed, orfalse
if 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 theregisterLogContext
RuntimePermission
.- 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 theunregisterLogContext
RuntimePermission
.- Parameters:
classLoader
- the classloaderlogContext
- the log context- Returns:
true
if the association exists and was removed,false
otherwise
-
-