Class MDC


  • public final class MDC
    extends java.lang.Object
    Mapped diagnostic context. Each log provider implementation may behave different.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private MDC()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void clear()
      Clears the message diagnostics context.
      static java.lang.Object get​(java.lang.String key)
      Returns the value for the key or null if no value was found.
      static java.util.Map<java.lang.String,​java.lang.Object> getMap()
      Returns the map from the context.
      static java.lang.Object put​(java.lang.String key, java.lang.Object val)
      Puts the value onto the context.
      static void remove​(java.lang.String key)
      Removes the value from the context.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MDC

        private MDC()
    • Method Detail

      • put

        public static java.lang.Object put​(java.lang.String key,
                                           java.lang.Object val)
        Puts the value onto the context.
        Parameters:
        key - the key for the value
        val - the value
        Returns:
        the previous value set or null if no value was set
      • get

        public static java.lang.Object get​(java.lang.String key)
        Returns the value for the key or null if no value was found.
        Parameters:
        key - the key to lookup the value for
        Returns:
        the value or null if not found
      • remove

        public static void remove​(java.lang.String key)
        Removes the value from the context.
        Parameters:
        key - the key of the value to remove
      • getMap

        public static java.util.Map<java.lang.String,​java.lang.Object> getMap()
        Returns the map from the context.

        Note that in most implementations this is an expensive operation and should be used sparingly.

        Returns:
        the map from the context or an empty map if the context is null
      • clear

        public static void clear()
        Clears the message diagnostics context.