Log4j 1.3alpha-8

org.apache.log4j
Class MDC

java.lang.Object
  |
  +--org.apache.log4j.MDC

public class MDC
extends Object

The MDC class is similar to the NDC 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
Author:
Ceki Gülcü

Method Summary
static void clear()
          Clear all entries in the MDC.
static Object get(String key)
          Get the context identified by the key parameter.
static Hashtable getContext()
          Get the current thread's MDC as a hashtable.
static Enumeration getKeys()
          Returns the keys in the MDC as an Enumeration.
static void put(String key, Object val)
          Deprecated. please use the put(String key, String val) form.
static void put(String key, String val)
          Put a context value (the val parameter) as identified with the key parameter into the current thread's context map.
static void remove(String key)
          Remove the the context identified by the key parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

put

public static void put(String key,
                       String val)
Put a context value (the val parameter) as identified with the key 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.


put

public static void put(String key,
                       Object val)
Deprecated. please use the put(String key, String val) form.

Please use the put(String key, String val) form instead. The 'val' parameter needs to be a string.
Parameters:
key - the key for the contextual information
val - is transformed into a string before being placed in the MDC

get

public static Object get(String key)
Get the context identified by the key parameter.

This method has no side effects.


remove

public static void remove(String key)
Remove the the context identified by the key parameter.

clear

public static void clear()
Clear all entries in the MDC.
Since:
1.3

getContext

public static Hashtable getContext()
Get the current thread's MDC as a hashtable. This method is intended to be used internally.

getKeys

public static Enumeration getKeys()
Returns the keys in the MDC as an Enumeration. The returned value can be null.
Since:
version 1.3

Log4j 1.3alpha-8

Copyright © 2000-2006 Apache Software Foundation.
Licensed under the Apache License, Version 2.0.