public final class LogContext extends java.lang.Object implements Protectable
Modifier and Type | Class and Description |
---|---|
private static class |
LogContext.LazyHolder
This lazy holder class is required to prevent a problem due to a LogContext instance being constructed
before the class init is complete.
|
private static interface |
LogContext.LevelRef |
private static class |
LogContext.StrongLevelRef |
private static class |
LogContext.WeakLevelRef |
Modifier and Type | Field and Description |
---|---|
(package private) static java.security.Permission |
CONTROL_PERMISSION |
(package private) static java.security.Permission |
CREATE_CONTEXT_PERMISSION |
static LogContextSelector |
DEFAULT_LOG_CONTEXT_SELECTOR
The default log context selector, which always returns the system log context.
|
private java.lang.ThreadLocal<java.lang.Boolean> |
granted |
private java.util.concurrent.atomic.AtomicReference<java.util.Map<java.lang.String,LogContext.LevelRef>> |
levelMapReference |
private static LogContextSelector |
logContextSelector |
private java.util.concurrent.ConcurrentSkipListMap<java.lang.String,java.util.concurrent.atomic.AtomicInteger> |
loggerNames |
private java.util.logging.LoggingMXBean |
mxBean |
private java.lang.Object |
protectKey |
private static java.util.concurrent.atomic.AtomicReferenceFieldUpdater<LogContext,java.lang.Object> |
protectKeyUpdater |
private LoggerNode |
rootLogger |
(package private) static java.security.Permission |
SET_CONTEXT_SELECTOR_PERMISSION |
private boolean |
strong |
private static LogContext |
SYSTEM_CONTEXT |
(package private) java.lang.Object |
treeLock
This lock is taken any time a change is made which affects multiple nodes in the hierarchy.
|
Constructor and Description |
---|
LogContext(boolean strong) |
Modifier and Type | Method and Description |
---|---|
private static java.lang.SecurityException |
accessDenied() |
(package private) static void |
checkAccess(LogContext logContext) |
(package private) static void |
checkSecurityAccess() |
static LogContext |
create()
Create a new log context.
|
static LogContext |
create(boolean strong)
Create a new log context.
|
(package private) java.util.concurrent.ConcurrentMap<java.lang.String,LoggerNode> |
createChildMap() |
protected void |
decrementRef(java.lang.String name) |
void |
disableAccess()
Disable previous access to the object for modifications on the current thread.
|
void |
enableAccess(java.lang.Object protectKey)
Enable access to the object for modifications on the current thread.
|
<V> V |
getAttachment(java.lang.String loggerName,
Logger.AttachmentKey<V> key)
Get a logger attachment for a logger name, if it exists.
|
java.util.logging.Level |
getLevelForName(java.lang.String name)
Get the level for a name.
|
static LogContext |
getLogContext()
Get the currently active log context.
|
Logger |
getLogger(java.lang.String name)
Get a logger with the given name from this logging context.
|
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.
|
java.util.Enumeration<java.lang.String> |
getLoggerNames()
Returns an enumeration of the logger names that have been created.
|
java.util.logging.LoggingMXBean |
getLoggingMXBean()
Get the
LoggingMXBean associated with this log context. |
(package private) LoggerNode |
getRootLoggerNode() |
static LogContext |
getSystemLogContext()
Get the system log context.
|
protected void |
incrementRef(java.lang.String name) |
void |
protect(java.lang.Object protectionKey)
Protect this object from modifications.
|
void |
registerLevel(java.util.logging.Level level)
Register a level instance with this log context.
|
static void |
setLogContextSelector(LogContextSelector newSelector)
Set a new log context selector.
|
void |
unprotect(java.lang.Object protectionKey)
Allows the object to be modified if the
protectionKey matches the key used to protect the object. |
void |
unregisterLevel(java.util.logging.Level level)
Unregister a previously registered level.
|
private static final LogContext SYSTEM_CONTEXT
static final java.security.Permission CREATE_CONTEXT_PERMISSION
static final java.security.Permission SET_CONTEXT_SELECTOR_PERMISSION
static final java.security.Permission CONTROL_PERMISSION
private final LoggerNode rootLogger
private final java.util.logging.LoggingMXBean mxBean
private final boolean strong
private final java.util.concurrent.ConcurrentSkipListMap<java.lang.String,java.util.concurrent.atomic.AtomicInteger> loggerNames
private volatile java.lang.Object protectKey
private final java.lang.ThreadLocal<java.lang.Boolean> granted
private static final java.util.concurrent.atomic.AtomicReferenceFieldUpdater<LogContext,java.lang.Object> protectKeyUpdater
private final java.util.concurrent.atomic.AtomicReference<java.util.Map<java.lang.String,LogContext.LevelRef>> levelMapReference
final java.lang.Object treeLock
public static final LogContextSelector DEFAULT_LOG_CONTEXT_SELECTOR
private static volatile LogContextSelector logContextSelector
public static LogContext create(boolean strong)
"createLogContext"
RuntimePermission
to invoke this method.strong
- true
if the context should use strong references, false
to use (default) weak
references for automatic logger GCpublic static LogContext create()
"createLogContext"
RuntimePermission
to invoke this method.public Logger getLogger(java.lang.String name)
name
- the logger nameLogManager.getLogger(String)
public Logger getLoggerIfExists(java.lang.String name)
name
- the logger namenull
if no such logger node existspublic <V> V getAttachment(java.lang.String loggerName, Logger.AttachmentKey<V> key)
V
- the attachment value typeloggerName
- the logger namekey
- the attachment keynull
if the logger or the attachment does not existpublic java.util.logging.LoggingMXBean getLoggingMXBean()
LoggingMXBean
associated with this log context.LoggingMXBean
instancepublic java.util.logging.Level getLevelForName(java.lang.String name) throws java.lang.IllegalArgumentException
name
- the namejava.lang.IllegalArgumentException
- if the name is not knownpublic void registerLevel(java.util.logging.Level level)
level
- the level to registerpublic void unregisterLevel(java.util.logging.Level level)
level
- the level to unregisterpublic static LogContext getSystemLogContext()
public static LogContext getLogContext()
public static void setLogContextSelector(LogContextSelector newSelector)
"setLogContextSelector"
RuntimePermission
to invoke this method.newSelector
- the new selector.public void protect(java.lang.Object protectionKey) throws java.lang.SecurityException
Protectable
protect
in interface Protectable
protectionKey
- the key used to protect the object.java.lang.SecurityException
- if the object is already protected.public void unprotect(java.lang.Object protectionKey) throws java.lang.SecurityException
Protectable
protectionKey
matches the key used to protect
the object.unprotect
in interface Protectable
protectionKey
- the key used to protect the object.java.lang.SecurityException
- if the object is protected and the key doesn't match.public void enableAccess(java.lang.Object protectKey) throws java.lang.SecurityException
Protectable
enableAccess
in interface Protectable
protectKey
- the key used to protect
modifications.java.lang.SecurityException
public void disableAccess()
Protectable
disableAccess
in interface Protectable
public java.util.Enumeration<java.lang.String> getLoggerNames()
LogManager.getLoggerNames()
protected void incrementRef(java.lang.String name)
protected void decrementRef(java.lang.String name)
private static java.lang.SecurityException accessDenied()
static void checkSecurityAccess()
static void checkAccess(LogContext logContext)
LoggerNode getRootLoggerNode()
java.util.concurrent.ConcurrentMap<java.lang.String,LoggerNode> createChildMap()