Package org.apache.logging.log4j.spi
Interface LoggerContext
-
- All Known Implementing Classes:
SimpleLoggerContext
public interface LoggerContext
Anchor point for logging implementations.
-
-
Field Summary
Fields Modifier and Type Field Description static LoggerContext[]
EMPTY_ARRAY
Empty array.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Object
getExternalContext()
Gets the anchor for some other context, such as a ClassLoader or ServletContext.default ExtendedLogger
getLogger(Class<?> cls)
Gets an ExtendedLogger using the fully qualified name of the Class as the Logger name.default ExtendedLogger
getLogger(Class<?> cls, MessageFactory messageFactory)
Gets an ExtendedLogger using the fully qualified name of the Class as the Logger name.ExtendedLogger
getLogger(String name)
Gets an ExtendedLogger.ExtendedLogger
getLogger(String name, MessageFactory messageFactory)
Gets an ExtendedLogger.default LoggerRegistry<? extends Logger>
getLoggerRegistry()
Gets the LoggerRegistry.default Object
getObject(String key)
Gets an object by its name.boolean
hasLogger(String name)
Tests if a Logger with the specified name exists.boolean
hasLogger(String name, Class<? extends MessageFactory> messageFactoryClass)
Tests if a Logger with the specified name and MessageFactory type exists.boolean
hasLogger(String name, MessageFactory messageFactory)
Tests if a Logger with the specified name and MessageFactory exists.default Object
putObject(String key, Object value)
Associates an object into the LoggerContext by name for later use.default Object
putObjectIfAbsent(String key, Object value)
Associates an object into the LoggerContext by name for later use if an object is not already stored with that key.default Object
removeObject(String key)
Removes an object if it is present.default boolean
removeObject(String key, Object value)
Removes an object if it is present and the provided object is stored.
-
-
-
Field Detail
-
EMPTY_ARRAY
static final LoggerContext[] EMPTY_ARRAY
Empty array.
-
-
Method Detail
-
getExternalContext
Object getExternalContext()
Gets the anchor for some other context, such as a ClassLoader or ServletContext.- Returns:
- The external context.
-
getLogger
default ExtendedLogger getLogger(Class<?> cls)
Gets an ExtendedLogger using the fully qualified name of the Class as the Logger name.- Parameters:
cls
- The Class whose name should be used as the Logger name.- Returns:
- The logger.
- Since:
- 2.14.0
-
getLogger
default ExtendedLogger getLogger(Class<?> cls, MessageFactory messageFactory)
Gets an ExtendedLogger using the fully qualified name of the Class as the Logger name.- Parameters:
cls
- The Class whose name should be used as the Logger name.messageFactory
- The message factory is used only when creating a logger, subsequent use does not change the logger but will log a warning if mismatched.- Returns:
- The logger.
- Since:
- 2.14.0
-
getLogger
ExtendedLogger getLogger(String name)
Gets an ExtendedLogger.- Parameters:
name
- The name of the Logger to return.- Returns:
- The logger with the specified name.
-
getLogger
ExtendedLogger getLogger(String name, MessageFactory messageFactory)
Gets an ExtendedLogger.- Parameters:
name
- The name of the Logger to return.messageFactory
- The message factory is used only when creating a logger, subsequent use does not change the logger but will log a warning if mismatched.- Returns:
- The logger with the specified name.
-
getLoggerRegistry
default LoggerRegistry<? extends Logger> getLoggerRegistry()
Gets the LoggerRegistry.- Returns:
- the LoggerRegistry.
- Since:
- 2.17.2
-
getObject
default Object getObject(String key)
Gets an object by its name.- Parameters:
key
- The object's key.- Returns:
- The Object that is associated with the key, if any.
- Since:
- 2.13.0
-
hasLogger
boolean hasLogger(String name)
Tests if a Logger with the specified name exists.- Parameters:
name
- The Logger name to search for.- Returns:
- true if the Logger exists, false otherwise.
-
hasLogger
boolean hasLogger(String name, Class<? extends MessageFactory> messageFactoryClass)
Tests if a Logger with the specified name and MessageFactory type exists.- Parameters:
name
- The Logger name to search for.messageFactoryClass
- The message factory class to search for.- Returns:
- true if the Logger exists, false otherwise.
- Since:
- 2.5
-
hasLogger
boolean hasLogger(String name, MessageFactory messageFactory)
Tests if a Logger with the specified name and MessageFactory exists.- Parameters:
name
- The Logger name to search for.messageFactory
- The message factory to search for.- Returns:
- true if the Logger exists, false otherwise.
- Since:
- 2.5
-
putObject
default Object putObject(String key, Object value)
Associates an object into the LoggerContext by name for later use.- Parameters:
key
- The object's key.value
- The object.- Returns:
- The previous object or null.
- Since:
- 2.13.0
-
putObjectIfAbsent
default Object putObjectIfAbsent(String key, Object value)
Associates an object into the LoggerContext by name for later use if an object is not already stored with that key.- Parameters:
key
- The object's key.value
- The object.- Returns:
- The previous object or null.
- Since:
- 2.13.0
-
removeObject
default Object removeObject(String key)
Removes an object if it is present.- Parameters:
key
- The object's key.- Returns:
- The object if it was present, null if it was not.
- Since:
- 2.13.0
-
-