Top Description Fields Methods
org.apache.logging.log4j.spi

public Interface LoggerContext

Known Direct Implementers
org.apache.logging.log4j.simple.SimpleLoggerContext
Imports
org.apache.logging.log4j.Logger, org.apache.logging.log4j.message.MessageFactory

Anchor point for logging implementations.

Field Summary

Modifier and TypeField and Description
public static final LoggerContext[]
EMPTY_ARRAY

Empty array.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

The external context.
getExternalContext
()

Gets the anchor for some other context, such as a ClassLoader or ServletContext.

public default ExtendedLogger

Returns:

The logger.
getLogger
(Class<?>
The Class whose name should be used as the Logger name.
cls
)

Gets an ExtendedLogger using the fully qualified name of the Class as the Logger name.

public default ExtendedLogger

Returns:

The logger.
getLogger
(Class<?>
The Class whose name should be used as the Logger name.
cls
,
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.
messageFactory
)

Gets an ExtendedLogger using the fully qualified name of the Class as the Logger name.

public ExtendedLogger

Returns:

The logger with the specified name.
getLogger
(String
The name of the Logger to return.
name
)

Gets an ExtendedLogger.

public ExtendedLogger

Returns:

The logger with the specified name.
getLogger
(String
The name of the Logger to return.
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.
messageFactory
)

Gets an ExtendedLogger.

public default LoggerRegistry<? extends Logger>

Returns:

the LoggerRegistry.
getLoggerRegistry
()

Gets the LoggerRegistry.

public default Object

Returns:

The Object that is associated with the key, if any.
getObject
(String
The object's key.
key
)

Gets an object by its name.

public boolean

Returns:

true if the Logger exists, false otherwise.
hasLogger
(String
The Logger name to search for.
name
)

Tests if a Logger with the specified name exists.

public boolean

Returns:

true if the Logger exists, false otherwise.
hasLogger
(String
The Logger name to search for.
name
,
Class<? extends MessageFactory>
The message factory class to search for.
messageFactoryClass
)

Tests if a Logger with the specified name and MessageFactory type exists.

public boolean

Returns:

true if the Logger exists, false otherwise.
hasLogger
(String
The Logger name to search for.
name
,
MessageFactory
The message factory to search for.
messageFactory
)

Tests if a Logger with the specified name and MessageFactory exists.

public default Object

Returns:

The previous object or null.
putObject
(String
The object's key.
key
,
Object
The object.
value
)

Associates an object into the LoggerContext by name for later use.

public default Object

Returns:

The previous object or null.
putObjectIfAbsent
(String
The object's key.
key
,
Object
The object.
value
)

Associates an object into the LoggerContext by name for later use if an object is not already stored with that key.

public default Object

Returns:

The object if it was present, null if it was not.
removeObject
(String
The object's key.
key
)

Removes an object if it is present.

public default boolean

Returns:

The object if it was present, null if it was not.
removeObject
(String
The object's key.
key
,
Object
The object.
value
)

Removes an object if it is present and the provided object is stored.

Field Detail

EMPTY_ARRAYback to summary
public static final LoggerContext[] EMPTY_ARRAY

Empty array.

Method Detail

getExternalContextback to summary
public Object getExternalContext()

Gets the anchor for some other context, such as a ClassLoader or ServletContext.

Returns:Object

The external context.

getLoggerback to summary
public default ExtendedLogger getLogger(Class<?> cls)

Gets an ExtendedLogger using the fully qualified name of the Class as the Logger name.

Parameters
cls:Class<?>

The Class whose name should be used as the Logger name.

Returns:ExtendedLogger

The logger.

Since
2.14.0
getLoggerback to summary
public default ExtendedLogger getLogger(Class<?> cls, MessageFactory messageFactory)

Gets an ExtendedLogger using the fully qualified name of the Class as the Logger name.

Parameters
cls:Class<?>

The Class whose name should be used as the Logger name.

messageFactory: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:ExtendedLogger

The logger.

Since
2.14.0
getLoggerback to summary
public ExtendedLogger getLogger(String name)

Gets an ExtendedLogger.

Parameters
name:String

The name of the Logger to return.

Returns:ExtendedLogger

The logger with the specified name.

getLoggerback to summary
public ExtendedLogger getLogger(String name, MessageFactory messageFactory)

Gets an ExtendedLogger.

Parameters
name:String

The name of the Logger to return.

messageFactory: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:ExtendedLogger

The logger with the specified name.

getLoggerRegistryback to summary
public default LoggerRegistry<? extends Logger> getLoggerRegistry()

Gets the LoggerRegistry.

Returns:LoggerRegistry<? extends Logger>

the LoggerRegistry.

Since
2.17.2
getObjectback to summary
public default Object getObject(String key)

Gets an object by its name.

Parameters
key:String

The object's key.

Returns:Object

The Object that is associated with the key, if any.

Since
2.13.0
hasLoggerback to summary
public boolean hasLogger(String name)

Tests if a Logger with the specified name exists.

Parameters
name:String

The Logger name to search for.

Returns:boolean

true if the Logger exists, false otherwise.

hasLoggerback to summary
public boolean hasLogger(String name, Class<? extends MessageFactory> messageFactoryClass)

Tests if a Logger with the specified name and MessageFactory type exists.

Parameters
name:String

The Logger name to search for.

messageFactoryClass:Class<? extends MessageFactory>

The message factory class to search for.

Returns:boolean

true if the Logger exists, false otherwise.

Since
2.5
hasLoggerback to summary
public boolean hasLogger(String name, MessageFactory messageFactory)

Tests if a Logger with the specified name and MessageFactory exists.

Parameters
name:String

The Logger name to search for.

messageFactory:MessageFactory

The message factory to search for.

Returns:boolean

true if the Logger exists, false otherwise.

Since
2.5
putObjectback to summary
public default Object putObject(String key, Object value)

Associates an object into the LoggerContext by name for later use.

Parameters
key:String

The object's key.

value:Object

The object.

Returns:Object

The previous object or null.

Since
2.13.0
putObjectIfAbsentback to summary
public 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:String

The object's key.

value:Object

The object.

Returns:Object

The previous object or null.

Since
2.13.0
removeObjectback to summary
public default Object removeObject(String key)

Removes an object if it is present.

Parameters
key:String

The object's key.

Returns:Object

The object if it was present, null if it was not.

Since
2.13.0
removeObjectback to summary
public default boolean removeObject(String key, Object value)

Removes an object if it is present and the provided object is stored.

Parameters
key:String

The object's key.

value:Object

The object.

Returns:boolean

The object if it was present, null if it was not.

Since
2.13.0