java.lang.Object
org.jboss.logmanager.LogContext
- All Implemented Interfaces:
AutoCloseable
A logging context, for producing isolated logging environments.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final LogContextSelectorThe default log context selector, which always returns the system log context. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCloseHandler(AutoCloseable closeHandler) Adds a handler invoked during the close of this log context.<V> Vattach(Logger.AttachmentKey<V> key, V value) Attach an object to this log context under a given key.<V> VattachIfAbsent(Logger.AttachmentKey<V> key, V value) Attach an object to this log context under a given key, if such an attachment does not already exist.voidclose()static LogContextcreate()Create a new log context.static LogContextcreate(boolean strong) Create a new log context.static LogContextcreate(boolean strong, LogContextInitializer initializer) Create a new log context.static LogContextcreate(LogContextInitializer initializer) Create a new log context.<V> Vdetach(Logger.AttachmentKey<V> key) Remove an attachment.<V> VgetAttachment(String loggerName, Logger.AttachmentKey<V> key) Get a logger attachment for a logger name, if it exists.<V> VgetAttachment(Logger.AttachmentKey<V> key) Get the attachment value for a given key, ornullif there is no such attachment.Gets the current close handlers associated with this log context.getLevelForName(String name) Get the level for a name.static LogContextGet the currently active log context.static LogContextSelectorReturns the currently set log context selector.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.static LogContextGet the system log context.voidregisterLevel(Level level) Register a level instance with this log context.voidregisterLevel(Level level, boolean strong) Register a level instance with this log context.voidsetCloseHandlers(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 voidsetLogContextSelector(LogContextSelector newSelector) Set a new log context selector.voidunregisterLevel(Level level) Unregister a previously registered level.
-
Field Details
-
DEFAULT_LOG_CONTEXT_SELECTOR
The default log context selector, which always returns the system log context.
-
-
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.- Parameters:
strong-trueif the context should use strong references,falseto use (default) weak references for automatic logger GCinitializer- the log context initializer to use (must not benull)- 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
-
create
Create a new log context. If a security manager is installed, the caller must have the"createLogContext"RuntimePermissionto invoke this method.- Parameters:
initializer- the log context initializer to use (must not benull)- Returns:
- a new log context
-
getAttachment
Get the attachment value for a given key, ornullif there is no such attachment. Log context attachments are placed on the root logger and can also be accessed there.- Type Parameters:
V- the attachment value type- Parameters:
key- the key- Returns:
- the attachment, or
nullif there is none for this key
-
attach
Attach an object to this log context under a given key. A strong reference is maintained to the key and value for as long as this log context exists. Log context attachments are placed on the root logger and can also be accessed there.- Type Parameters:
V- the attachment value type- Parameters:
key- the attachment keyvalue- the attachment value- Returns:
- the old attachment, if there was one
- Throws:
SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)IllegalArgumentException- if the attachment cannot be added because the maximum has been reached
-
attachIfAbsent
Attach an object to this log context under a given key, if such an attachment does not already exist. A strong reference is maintained to the key and value for as long as this log context exists. Log context attachments are placed on the root logger and can also be accessed there.- Type Parameters:
V- the attachment value type- Parameters:
key- the attachment keyvalue- the attachment value- Returns:
- the current attachment, if there is one, or
nullif the value was successfully attached - Throws:
SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)IllegalArgumentException- if the attachment cannot be added because the maximum has been reached
-
detach
Remove an attachment. Log context attachments are placed on the root logger and can also be accessed there.- Type Parameters:
V- the attachment value type- Parameters:
key- the attachment key- Returns:
- the old value, or
nullif there was none - Throws:
SecurityException- if a security manager exists and if the caller does not haveLoggingPermission(control)
-
getLogger
Get a logger with the given name from this logging context.- Parameters:
name- the logger name- Returns:
- the logger instance
- See Also:
-
getLoggerIfExists
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
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
-
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
-
registerLevel
Register a level instance with this log context. The level can then be looked up by name. Any previous level registration for the given level's name will be overwritten.- Parameters:
level- the level to registerstrong-trueto strongly reference the level, orfalseto weakly reference it
-
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.
-
getLogContextSelector
Returns the currently set log context selector.- Returns:
- the log context selector
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
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:
-
addCloseHandler
Adds a handler invoked during the close of this log context. The close handlers will be invoked in the order they are added.The loggers associated with this context will always be closed.
- Parameters:
closeHandler- the close handler to use
-
getCloseHandlers
Gets the current close handlers associated with this log context.- Returns:
- the current close handlers
-
setCloseHandlers
Clears any current close handlers associated with log context, then adds the handlers to be invoked during the close of this log context. The close handlers will be invoked in the order they are added.The loggers associated with this context will always be closed.
- Parameters:
closeHandlers- the close handlers to use
-