Package org.apache.log4j
Class MDC
- java.lang.Object
-
- org.apache.log4j.MDC
-
public class MDC extends Object
The MDC class is similar to theNDCclass except that it is based on a map instead of a stack. It provides mapped diagnostic contexts. A Mapped Diagnostic Context, or MDC in short, is an instrument for distinguishing interleaved log output from different sources. Log output is typically interleaved when a server handles multiple clients near-simultaneously.The MDC is managed on a per thread basis. A child thread automatically inherits a copy of the mapped diagnostic context of its parent.
The MDC class requires JDK 1.2 or above. Under JDK 1.1 the MDC will always return empty values but otherwise will not affect or harm your application.
- Since:
- 1.2
- Author:
- Ceki Gülcü
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclear()Remove all values from the MDC.static Objectget(String key)Get the context identified by thekeyparameter.static Map<?,?>getContext()Get the current thread's MDC as a hashtable.static voidput(String key, Object o)Put a context value (theoparameter) as identified with thekeyparameter into the current thread's context map.static voidremove(String key)Remove the the context identified by thekeyparameter.
-
-
-
Method Detail
-
put
public static void put(String key, Object o)
Put a context value (theoparameter) as identified with thekeyparameter into the current thread's context map.If the current thread does not have a context map it is created as a side effect.
-
get
public static Object get(String key)
Get the context identified by thekeyparameter.This method has no side effects.
-
remove
public static void remove(String key)
Remove the the context identified by thekeyparameter.
-
getContext
public static Map<?,?> getContext()
-
clear
public static void clear()
Remove all values from the MDC.- Since:
- 1.2.16
-
-