Class SLF4JMappedDiagnosticContext
java.lang.Object
org.tentackle.log.AbstractMappedDiagnosticContext
org.tentackle.log.slf4j.SLF4JMappedDiagnosticContext
- All Implemented Interfaces:
MappedDiagnosticContext
@Service(SLF4JMappedDiagnosticContext.class)
public class SLF4JMappedDiagnosticContext
extends AbstractMappedDiagnosticContext
The mapped diagnostic context for SLF4J.
Delegates to SLF4J's thread-local MDC, so the keys can be referenced in the
backend's layout patterns (e.g. %X in Logback).
The singleton is created via the ServiceFactory and can thus be replaced by an
application-specific @Service.
- Author:
- harald
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all entries in the MDC of the underlying implementation.Get the context identified by thekeyparameter.Gets the map.static SLF4JMappedDiagnosticContextGets the singleton.voidPut a context value (thevalparameter) as identified with thekeyparameter into the current thread's context map.voidRemoves the context identified by thekeyparameter using the underlying system's MDC implementation.Methods inherited from class AbstractMappedDiagnosticContext
getKeys, matchesPattern, toString
-
Constructor Details
-
SLF4JMappedDiagnosticContext
public SLF4JMappedDiagnosticContext()Creates the MDC for SLF4J.
-
-
Method Details
-
getInstance
-
put
Description copied from interface:MappedDiagnosticContextPut a context value (thevalparameter) as identified with thekeyparameter into the current thread's context map. Thekeyparameter cannot be null. Thevalparameter can be null only if the underlying implementation supports it.This method delegates all work to the MDC of the underlying logging system.
- Parameters:
key- the keyval- the value
-
get
Description copied from interface:MappedDiagnosticContextGet the context identified by thekeyparameter. Thekeyparameter cannot be null.This method delegates all work to the MDC of the underlying logging system.
- Parameters:
key- the key- Returns:
- the string value identified by the
keyparameter, null if none
-
remove
Description copied from interface:MappedDiagnosticContextRemoves the context identified by thekeyparameter using the underlying system's MDC implementation. Thekeyparameter cannot be null. This method does nothing if there is no previous value associated withkey.- Parameters:
key- the key
-
clear
public void clear()Description copied from interface:MappedDiagnosticContextClear all entries in the MDC of the underlying implementation. -
getContext
Gets the map.Note: may be a copy of the internal map, i.e. modifications may not show up in the real MDC.
SLF4J returns a copy of the current thread's context. If there is none, an empty mutable map is returned.
- Specified by:
getContextin classAbstractMappedDiagnosticContext- Returns:
- the key/value map, never null
-