Class LogContext
java.lang.Object
org.jboss.logmanager.LogContext
- All Implemented Interfaces:
Protectable
A logging context, for producing isolated logging environments.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classThis lazy holder class is required to prevent a problem due to a LogContext instance being constructed before the class init is complete.private static interfaceprivate static final classprivate static final class -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final Permission(package private) static final Permissionstatic final LogContextSelectorThe default log context selector, which always returns the system log context.private final ThreadLocal<Boolean> private final AtomicReference<Map<String, LogContext.LevelRef>> private static LogContextSelectorprivate final ConcurrentSkipListMap<String, AtomicInteger> private final LoggingMXBeanprivate Objectprivate static final AtomicReferenceFieldUpdater<LogContext, Object> private final LoggerNode(package private) static final Permissionprivate final booleanprivate static final LogContext(package private) final ObjectThis lock is taken any time a change is made which affects multiple nodes in the hierarchy. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static SecurityException(package private) static voidcheckAccess(LogContext logContext) (package private) static voidstatic LogContextcreate()Create a new log context.static LogContextcreate(boolean strong) Create a new log context.(package private) ConcurrentMap<String, LoggerNode> protected voiddecrementRef(String name) voidDisable previous access to the object for modifications on the current thread.voidenableAccess(Object protectKey) Enable access to the object for modifications on the current thread.<V> VgetAttachment(String loggerName, Logger.AttachmentKey<V> key) Get a logger attachment for a logger name, if it exists.getLevelForName(String name) Get the level for a name.static LogContextGet the currently active log context.Get a logger with the given name from this logging context.getLoggerIfExists(String name) Get a logger with the given name from this logging context, if a logger node exists at that location.Returns an enumeration of the logger names that have been created.Get theLoggingMXBeanassociated with this log context.(package private) LoggerNodestatic LogContextGet the system log context.protected voidincrementRef(String name) voidProtect this object from modifications.voidregisterLevel(Level level) Register a level instance with this log context.static voidsetLogContextSelector(LogContextSelector newSelector) Set a new log context selector.voidAllows the object to be modified if theprotectionKeymatches the key used toprotectthe object.voidunregisterLevel(Level level) Unregister a previously registered level.
-
Field Details
-
SYSTEM_CONTEXT
-
CREATE_CONTEXT_PERMISSION
-
SET_CONTEXT_SELECTOR_PERMISSION
-
CONTROL_PERMISSION
-
rootLogger
-
mxBean
-
strong
private final boolean strong -
loggerNames
-
protectKey
-
granted
-
protectKeyUpdater
-
levelMapReference
-
treeLock
This lock is taken any time a change is made which affects multiple nodes in the hierarchy. -
DEFAULT_LOG_CONTEXT_SELECTOR
The default log context selector, which always returns the system log context. -
logContextSelector
-
-
Constructor Details
-
LogContext
LogContext(boolean strong)
-
-
Method Details
-
create
Create a new log context. If a security manager is installed, the caller must have the"createLogContext"RuntimePermissionto invoke this method.- Parameters:
strong-trueif the context should use strong references,falseto use (default) weak references for automatic logger GC- Returns:
- a new log context
-
create
Create a new log context. If a security manager is installed, the caller must have the"createLogContext"RuntimePermissionto invoke this method.- Returns:
- a new log context
-
getLogger
-
getLoggerIfExists
-
getAttachment
Get a logger attachment for a logger name, if it exists.- Type Parameters:
V- the attachment value type- Parameters:
loggerName- the logger namekey- the attachment key- Returns:
- the attachment or
nullif the logger or the attachment does not exist
-
getLoggingMXBean
Get theLoggingMXBeanassociated with this log context.- Returns:
- the
LoggingMXBeaninstance
-
getLevelForName
Get the level for a name.- Parameters:
name- the name- Returns:
- the level
- Throws:
IllegalArgumentException- if the name is not known
-
registerLevel
Register a level instance with this log context. The level can then be looked up by name. Only a weak reference to the level instance will be kept. Any previous level registration for the given level's name will be overwritten.- Parameters:
level- the level to register
-
unregisterLevel
Unregister a previously registered level. Log levels that are not registered may still be used, they just will not be findable by name.- Parameters:
level- the level to unregister
-
getSystemLogContext
Get the system log context.- Returns:
- the system log context
-
getLogContext
Get the currently active log context.- Returns:
- the currently active log context
-
setLogContextSelector
Set a new log context selector. If a security manager is installed, the caller must have the"setLogContextSelector"RuntimePermissionto invoke this method.- Parameters:
newSelector- the new selector.
-
protect
Description copied from interface:ProtectableProtect this object from modifications.- Specified by:
protectin interfaceProtectable- Parameters:
protectionKey- the key used to protect the object.- Throws:
SecurityException- if the object is already protected.
-
unprotect
Description copied from interface:ProtectableAllows the object to be modified if theprotectionKeymatches the key used toprotectthe object.- Specified by:
unprotectin interfaceProtectable- Parameters:
protectionKey- the key used to protect the object.- Throws:
SecurityException- if the object is protected and the key doesn't match.
-
enableAccess
Description copied from interface:ProtectableEnable access to the object for modifications on the current thread.- Specified by:
enableAccessin interfaceProtectable- Parameters:
protectKey- the key used toprotectmodifications.- Throws:
SecurityException
-
disableAccess
public void disableAccess()Description copied from interface:ProtectableDisable previous access to the object for modifications on the current thread.- Specified by:
disableAccessin interfaceProtectable
-
getLoggerNames
Returns an enumeration of the logger names that have been created. This does not return names of loggers that may have been garbage collected. Logger names added after the enumeration has been retrieved may also be added to the enumeration.- Returns:
- an enumeration of the logger names
- See Also:
-
incrementRef
-
decrementRef
-
accessDenied
-
checkSecurityAccess
static void checkSecurityAccess() -
checkAccess
-
getRootLoggerNode
LoggerNode getRootLoggerNode() -
createChildMap
ConcurrentMap<String, LoggerNode> createChildMap()
-