Package org.jboss.logmanager
Class LogContext
- java.lang.Object
-
- org.jboss.logmanager.LogContext
-
- All Implemented Interfaces:
Protectable
public final class LogContext extends java.lang.Object implements Protectable
A logging context, for producing isolated logging environments.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classLogContext.LazyHolderThis lazy holder class is required to prevent a problem due to a LogContext instance being constructed before the class init is complete.private static interfaceLogContext.LevelRefprivate static classLogContext.StrongLevelRefprivate static classLogContext.WeakLevelRef
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.security.PermissionCONTROL_PERMISSION(package private) static java.security.PermissionCREATE_CONTEXT_PERMISSIONstatic LogContextSelectorDEFAULT_LOG_CONTEXT_SELECTORThe default log context selector, which always returns the system log context.private java.lang.ThreadLocal<java.lang.Boolean>grantedprivate java.util.concurrent.atomic.AtomicReference<java.util.Map<java.lang.String,LogContext.LevelRef>>levelMapReferenceprivate static LogContextSelectorlogContextSelectorprivate java.util.concurrent.ConcurrentSkipListMap<java.lang.String,java.util.concurrent.atomic.AtomicInteger>loggerNamesprivate java.util.logging.LoggingMXBeanmxBeanprivate java.lang.ObjectprotectKeyprivate static java.util.concurrent.atomic.AtomicReferenceFieldUpdater<LogContext,java.lang.Object>protectKeyUpdaterprivate LoggerNoderootLogger(package private) static java.security.PermissionSET_CONTEXT_SELECTOR_PERMISSIONprivate booleanstrongprivate static LogContextSYSTEM_CONTEXT(package private) java.lang.ObjecttreeLockThis lock is taken any time a change is made which affects multiple nodes in the hierarchy.
-
Constructor Summary
Constructors Constructor Description LogContext(boolean strong)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.SecurityExceptionaccessDenied()(package private) static voidcheckAccess(LogContext logContext)(package private) static voidcheckSecurityAccess()static LogContextcreate()Create a new log context.static LogContextcreate(boolean strong)Create a new log context.(package private) java.util.concurrent.ConcurrentMap<java.lang.String,LoggerNode>createChildMap()protected voiddecrementRef(java.lang.String name)voiddisableAccess()Disable previous access to the object for modifications on the current thread.voidenableAccess(java.lang.Object protectKey)Enable access to the object for modifications on the current thread.<V> VgetAttachment(java.lang.String loggerName, Logger.AttachmentKey<V> key)Get a logger attachment for a logger name, if it exists.java.util.logging.LevelgetLevelForName(java.lang.String name)Get the level for a name.static LogContextgetLogContext()Get the currently active log context.LoggergetLogger(java.lang.String name)Get a logger with the given name from this logging context.LoggergetLoggerIfExists(java.lang.String name)Get a logger with the given name from this logging context, if a logger node exists at that location.java.util.Enumeration<java.lang.String>getLoggerNames()Returns an enumeration of the logger names that have been created.java.util.logging.LoggingMXBeangetLoggingMXBean()Get theLoggingMXBeanassociated with this log context.(package private) LoggerNodegetRootLoggerNode()static LogContextgetSystemLogContext()Get the system log context.protected voidincrementRef(java.lang.String name)voidprotect(java.lang.Object protectionKey)Protect this object from modifications.voidregisterLevel(java.util.logging.Level level)Register a level instance with this log context.static voidsetLogContextSelector(LogContextSelector newSelector)Set a new log context selector.voidunprotect(java.lang.Object protectionKey)Allows the object to be modified if theprotectionKeymatches the key used toprotectthe object.voidunregisterLevel(java.util.logging.Level level)Unregister a previously registered level.
-
-
-
Field Detail
-
SYSTEM_CONTEXT
private static final LogContext SYSTEM_CONTEXT
-
CREATE_CONTEXT_PERMISSION
static final java.security.Permission CREATE_CONTEXT_PERMISSION
-
SET_CONTEXT_SELECTOR_PERMISSION
static final java.security.Permission SET_CONTEXT_SELECTOR_PERMISSION
-
CONTROL_PERMISSION
static final java.security.Permission CONTROL_PERMISSION
-
rootLogger
private final LoggerNode rootLogger
-
mxBean
private final java.util.logging.LoggingMXBean mxBean
-
strong
private final boolean strong
-
loggerNames
private final java.util.concurrent.ConcurrentSkipListMap<java.lang.String,java.util.concurrent.atomic.AtomicInteger> loggerNames
-
protectKey
private volatile java.lang.Object protectKey
-
granted
private final java.lang.ThreadLocal<java.lang.Boolean> granted
-
protectKeyUpdater
private static final java.util.concurrent.atomic.AtomicReferenceFieldUpdater<LogContext,java.lang.Object> protectKeyUpdater
-
levelMapReference
private final java.util.concurrent.atomic.AtomicReference<java.util.Map<java.lang.String,LogContext.LevelRef>> levelMapReference
-
treeLock
final java.lang.Object treeLock
This lock is taken any time a change is made which affects multiple nodes in the hierarchy.
-
DEFAULT_LOG_CONTEXT_SELECTOR
public static final LogContextSelector DEFAULT_LOG_CONTEXT_SELECTOR
The default log context selector, which always returns the system log context.
-
logContextSelector
private static volatile LogContextSelector logContextSelector
-
-
Method Detail
-
create
public static LogContext create(boolean strong)
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
public static LogContext 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
public Logger getLogger(java.lang.String name)
Get a logger with the given name from this logging context.- Parameters:
name- the logger name- Returns:
- the logger instance
- See Also:
LogManager.getLogger(String)
-
getLoggerIfExists
public Logger getLoggerIfExists(java.lang.String name)
Get a logger with the given name from this logging context, if a logger node exists at that location.- Parameters:
name- the logger name- Returns:
- the logger instance, or
nullif no such logger node exists
-
getAttachment
public <V> V getAttachment(java.lang.String loggerName, Logger.AttachmentKey<V> key)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
public java.util.logging.LoggingMXBean getLoggingMXBean()
Get theLoggingMXBeanassociated with this log context.- Returns:
- the
LoggingMXBeaninstance
-
getLevelForName
public java.util.logging.Level getLevelForName(java.lang.String name) throws java.lang.IllegalArgumentExceptionGet the level for a name.- Parameters:
name- the name- Returns:
- the level
- Throws:
java.lang.IllegalArgumentException- if the name is not known
-
registerLevel
public void registerLevel(java.util.logging.Level level)
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
public void unregisterLevel(java.util.logging.Level level)
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
public static LogContext getSystemLogContext()
Get the system log context.- Returns:
- the system log context
-
getLogContext
public static LogContext getLogContext()
Get the currently active log context.- Returns:
- the currently active log context
-
setLogContextSelector
public static void setLogContextSelector(LogContextSelector newSelector)
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
public void protect(java.lang.Object protectionKey) throws java.lang.SecurityExceptionDescription copied from interface:ProtectableProtect this object from modifications.- Specified by:
protectin interfaceProtectable- Parameters:
protectionKey- the key used to protect the object.- Throws:
java.lang.SecurityException- if the object is already protected.
-
unprotect
public void unprotect(java.lang.Object protectionKey) throws java.lang.SecurityExceptionDescription 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:
java.lang.SecurityException- if the object is protected and the key doesn't match.
-
enableAccess
public void enableAccess(java.lang.Object protectKey) throws java.lang.SecurityExceptionDescription 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:
java.lang.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
public java.util.Enumeration<java.lang.String> 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:
LogManager.getLoggerNames()
-
incrementRef
protected void incrementRef(java.lang.String name)
-
decrementRef
protected void decrementRef(java.lang.String name)
-
accessDenied
private static java.lang.SecurityException accessDenied()
-
checkSecurityAccess
static void checkSecurityAccess()
-
checkAccess
static void checkAccess(LogContext logContext)
-
getRootLoggerNode
LoggerNode getRootLoggerNode()
-
createChildMap
java.util.concurrent.ConcurrentMap<java.lang.String,LoggerNode> createChildMap()
-
-