Package org.jboss.logging
Class Log4j2LoggerProvider
- java.lang.Object
-
- org.jboss.logging.Log4j2LoggerProvider
-
- All Implemented Interfaces:
LoggerProvider
final class Log4j2LoggerProvider extends java.lang.Object implements LoggerProvider
-
-
Constructor Summary
Constructors Constructor Description Log4j2LoggerProvider()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearMdc()
Removes all entries from the message diagnostics context.void
clearNdc()
Clears the nested diagnostics context.Log4j2Logger
getLogger(java.lang.String name)
Returns a logger which is backed by a logger from the log provider.java.lang.Object
getMdc(java.lang.String key)
Returns the value for the key on the message diagnostics context ornull
if no value was found.java.util.Map<java.lang.String,java.lang.Object>
getMdcMap()
Returns the map from the context.java.lang.String
getNdc()
Retrieves the current values set for the nested diagnostics context.int
getNdcDepth()
The current depth of the nested diagnostics context.java.lang.String
peekNdc()
Peeks at the top value from the stack and returns it.java.lang.String
popNdc()
Pops top value from the stack and returns it.void
pushNdc(java.lang.String message)
Pushes a value to the nested diagnostics context stack.java.lang.Object
putMdc(java.lang.String key, java.lang.Object value)
Puts the value onto the message diagnostics context.void
removeMdc(java.lang.String key)
Removes the value from the message diagnostics context.void
setNdcMaxDepth(int maxDepth)
Sets maximum depth of the stack removing any entries below the maximum depth.
-
-
-
Method Detail
-
getLogger
public Log4j2Logger getLogger(java.lang.String name)
Description copied from interface:LoggerProvider
Returns a logger which is backed by a logger from the log provider.Note: this should never be
null
- Specified by:
getLogger
in interfaceLoggerProvider
- Parameters:
name
- the name of the logger- Returns:
- a logger for the log provider logger.
-
clearMdc
public void clearMdc()
Description copied from interface:LoggerProvider
Removes all entries from the message diagnostics context.- Specified by:
clearMdc
in interfaceLoggerProvider
-
putMdc
public java.lang.Object putMdc(java.lang.String key, java.lang.Object value)
Description copied from interface:LoggerProvider
Puts the value onto the message diagnostics context.- Specified by:
putMdc
in interfaceLoggerProvider
- Parameters:
key
- the key for the valuevalue
- the value- Returns:
- the previous value set or
null
if no value was set
-
getMdc
public java.lang.Object getMdc(java.lang.String key)
Description copied from interface:LoggerProvider
Returns the value for the key on the message diagnostics context ornull
if no value was found.- Specified by:
getMdc
in interfaceLoggerProvider
- Parameters:
key
- the key to lookup the value for- Returns:
- the value or
null
if not found
-
removeMdc
public void removeMdc(java.lang.String key)
Description copied from interface:LoggerProvider
Removes the value from the message diagnostics context.- Specified by:
removeMdc
in interfaceLoggerProvider
- Parameters:
key
- the key of the value to remove
-
getMdcMap
public java.util.Map<java.lang.String,java.lang.Object> getMdcMap()
Description copied from interface:LoggerProvider
Returns the map from the context.Note that in most implementations this is an expensive operation and should be used sparingly.
- Specified by:
getMdcMap
in interfaceLoggerProvider
- Returns:
- the map from the context or an empty map if the context is
null
-
clearNdc
public void clearNdc()
Description copied from interface:LoggerProvider
Clears the nested diagnostics context.- Specified by:
clearNdc
in interfaceLoggerProvider
-
getNdc
public java.lang.String getNdc()
Description copied from interface:LoggerProvider
Retrieves the current values set for the nested diagnostics context.- Specified by:
getNdc
in interfaceLoggerProvider
- Returns:
- the current value set or
null
if no value was set
-
getNdcDepth
public int getNdcDepth()
Description copied from interface:LoggerProvider
The current depth of the nested diagnostics context.- Specified by:
getNdcDepth
in interfaceLoggerProvider
- Returns:
- the current depth of the stack
-
popNdc
public java.lang.String popNdc()
Description copied from interface:LoggerProvider
Pops top value from the stack and returns it.- Specified by:
popNdc
in interfaceLoggerProvider
- Returns:
- the top value from the stack or an empty string if no value was set
-
peekNdc
public java.lang.String peekNdc()
Description copied from interface:LoggerProvider
Peeks at the top value from the stack and returns it.- Specified by:
peekNdc
in interfaceLoggerProvider
- Returns:
- the value or an empty string
-
pushNdc
public void pushNdc(java.lang.String message)
Description copied from interface:LoggerProvider
Pushes a value to the nested diagnostics context stack.- Specified by:
pushNdc
in interfaceLoggerProvider
- Parameters:
message
- the message to push
-
setNdcMaxDepth
public void setNdcMaxDepth(int maxDepth)
Description copied from interface:LoggerProvider
Sets maximum depth of the stack removing any entries below the maximum depth.- Specified by:
setNdcMaxDepth
in interfaceLoggerProvider
- Parameters:
maxDepth
- the maximum depth to set
-
-