public final class LogContext extends Object implements Protectable, AutoCloseable
Modifier and Type | Field and Description |
---|---|
static LogContextSelector |
DEFAULT_LOG_CONTEXT_SELECTOR
The default log context selector, which always returns the system log context.
|
Modifier and Type | Method and Description |
---|---|
void |
addCloseHandler(AutoCloseable closeHandler)
Adds a handler invoked during the close of this log context.
|
void |
close() |
static LogContext |
create()
Create a new log context.
|
static LogContext |
create(boolean strong)
Create a new log context.
|
protected void |
decrementRef(String name) |
void |
disableAccess()
Disable previous access to the object for modifications on the current thread.
|
void |
enableAccess(Object protectKey)
Enable access to the object for modifications on the current thread.
|
<V> V |
getAttachment(String loggerName,
Logger.AttachmentKey<V> key)
Get a logger attachment for a logger name, if it exists.
|
Set<AutoCloseable> |
getCloseHandlers()
Gets the current close handlers associated with this log context.
|
Level |
getLevelForName(String name)
Get the level for a name.
|
static LogContext |
getLogContext()
Get the currently active log context.
|
static LogContextSelector |
getLogContextSelector()
Returns the currently set log context selector.
|
Logger |
getLogger(String name)
Get a logger with the given name from this logging context.
|
Logger |
getLoggerIfExists(String name)
Get a logger with the given name from this logging context, if a logger node exists at that location.
|
Enumeration<String> |
getLoggerNames()
Returns an enumeration of the logger names that have been created.
|
LoggingMXBean |
getLoggingMXBean()
Get the
LoggingMXBean associated with this log context. |
static LogContext |
getSystemLogContext()
Get the system log context.
|
protected void |
incrementRef(String name) |
void |
protect(Object protectionKey)
Protect this object from modifications.
|
void |
registerLevel(Level level)
Register a level instance with this log context.
|
void |
setCloseHandlers(Collection<AutoCloseable> closeHandlers)
Clears any current close handlers associated with log context, then adds the handlers to be invoked during
the close of this log context.
|
static void |
setLogContextSelector(LogContextSelector newSelector)
Set a new log context selector.
|
void |
unprotect(Object protectionKey)
Allows the object to be modified if the
protectionKey matches the key used to protect the object. |
void |
unregisterLevel(Level level)
Unregister a previously registered level.
|
public static final LogContextSelector DEFAULT_LOG_CONTEXT_SELECTOR
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(String name)
name
- the logger nameLogManager.getLogger(String)
public Logger getLoggerIfExists(String name)
name
- the logger namenull
if no such logger node existspublic <V> V getAttachment(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 LoggingMXBean getLoggingMXBean()
LoggingMXBean
associated with this log context.LoggingMXBean
instancepublic Level getLevelForName(String name) throws IllegalArgumentException
name
- the nameIllegalArgumentException
- if the name is not knownpublic void registerLevel(Level level)
level
- the level to registerpublic void unregisterLevel(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 static LogContextSelector getLogContextSelector()
public void protect(Object protectionKey) throws SecurityException
Protectable
protect
in interface Protectable
protectionKey
- the key used to protect the object.SecurityException
- if the object is already protected.public void unprotect(Object protectionKey) throws SecurityException
Protectable
protectionKey
matches the key used to protect
the object.unprotect
in interface Protectable
protectionKey
- the key used to protect the object.SecurityException
- if the object is protected and the key doesn't match.public void enableAccess(Object protectKey) throws SecurityException
Protectable
enableAccess
in interface Protectable
protectKey
- the key used to protect
modifications.SecurityException
public void disableAccess()
Protectable
disableAccess
in interface Protectable
public void close() throws Exception
close
in interface AutoCloseable
Exception
public Enumeration<String> getLoggerNames()
LogManager.getLoggerNames()
public void addCloseHandler(AutoCloseable closeHandler)
The loggers associated with this context will always be closed.
closeHandler
- the close handler to usepublic Set<AutoCloseable> getCloseHandlers()
public void setCloseHandlers(Collection<AutoCloseable> closeHandlers)
The loggers associated with this context will always be closed.
closeHandlers
- the close handlers to useprotected void incrementRef(String name)
protected void decrementRef(String name)
Copyright © 2021 JBoss by Red Hat. All rights reserved.