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 Details

    • SLF4JMappedDiagnosticContext

      public SLF4JMappedDiagnosticContext()
      Creates the MDC for SLF4J.
  • Method Details

    • getInstance

      public static SLF4JMappedDiagnosticContext getInstance()
      Gets the singleton.
      Returns:
      the singleton
    • put

      public void put(String key, String val)
      Description copied from interface: MappedDiagnosticContext
      Put a context value (the val parameter) as identified with the key parameter into the current thread's context map. The key parameter cannot be null. The val parameter 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 key
      val - the value
    • get

      public String get(String key)
      Description copied from interface: MappedDiagnosticContext
      Get the context identified by the key parameter. The key parameter 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 key parameter, null if none
    • remove

      public void remove(String key)
      Description copied from interface: MappedDiagnosticContext
      Removes the context identified by the key parameter using the underlying system's MDC implementation. The key parameter cannot be null. This method does nothing if there is no previous value associated with key.
      Parameters:
      key - the key
    • clear

      public void clear()
      Description copied from interface: MappedDiagnosticContext
      Clear all entries in the MDC of the underlying implementation.
    • getContext

      public Map<String,String> 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:
      getContext in class AbstractMappedDiagnosticContext
      Returns:
      the key/value map, never null