Package org.apache.log4j
Class MDC
- java.lang.Object
-
- org.apache.log4j.MDC
-
public class MDC extends java.lang.Object
The MDC class is similar to theNDC
class 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
-
-
Constructor Summary
Constructors Modifier Constructor Description private
MDC()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
clear()
Remove all values from the MDC.private void
clear0()
static java.lang.Object
get(java.lang.String key)
Get the context identified by thekey
parameter.private java.lang.Object
get0(java.lang.String key)
static java.util.Hashtable
getContext()
Get the current thread's MDC as a hashtable.private java.util.Hashtable
getContext0()
static void
put(java.lang.String key, java.lang.Object o)
Put a context value (theo
parameter) as identified with thekey
parameter into the current thread's context map.private void
put0(java.lang.String key, java.lang.Object o)
static void
remove(java.lang.String key)
Remove the the context identified by thekey
parameter.private void
remove0(java.lang.String key)
-
-
-
Field Detail
-
mdc
static final MDC mdc
-
HT_SIZE
static final int HT_SIZE
- See Also:
- Constant Field Values
-
java1
boolean java1
-
tlm
java.lang.Object tlm
-
removeMethod
private java.lang.reflect.Method removeMethod
-
-
Method Detail
-
put
public static void put(java.lang.String key, java.lang.Object o)
Put a context value (theo
parameter) as identified with thekey
parameter 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 java.lang.Object get(java.lang.String key)
Get the context identified by thekey
parameter.This method has no side effects.
-
remove
public static void remove(java.lang.String key)
Remove the the context identified by thekey
parameter.
-
getContext
public static java.util.Hashtable getContext()
Get the current thread's MDC as a hashtable. This method is intended to be used internally.
-
clear
public static void clear()
Remove all values from the MDC.- Since:
- 1.2.16
-
put0
private void put0(java.lang.String key, java.lang.Object o)
-
get0
private java.lang.Object get0(java.lang.String key)
-
remove0
private void remove0(java.lang.String key)
-
getContext0
private java.util.Hashtable getContext0()
-
clear0
private void clear0()
-
-