SLF4J API
Version 1.4.3

org.slf4j
Class MDC

java.lang.Object
  extended by org.slf4j.MDC

public class MDC
extends Object

This class hides and serves as a substitute for the underlying logging system's MDC implementation.

If the underlying logging system offers MDC functionality, then SLF4J's MDC, i.e. this class, will delegate to the underlying system's MDC. Note that at this time, only two logging systems, namely log4j and logback, offer MDC functionality. If the undelying system does not support MDC, then SLF4J will silently drop MDC information.

Thus, as a SLF4J user, you can take advantage of MDC in the presence of log4j or logback, but without forcing log4j or logback as dependencies upon your users.

For more information on MDC please see the chapter on MDC in the logback manual.

Please note that all methods in this class are static.

Since:
1.4.1
Author:
Ceki Gülcü

Method Summary
static void clear()
          Clear all entries in the MDC of the underlying implementation.
static String get(String key)
          Get the context identified by the key parameter.
static MDCAdapter getMDCAdapter()
          Returns the MDCAdapter instance currently in use.
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 using the underlying system's MDC implementation.
 
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)
                throws IllegalArgumentException
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 code>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.

Throws:
IllegalArgumentException - in case the "key" parameter is null

get

public static String get(String key)
                  throws IllegalArgumentException
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.

Returns:
the string value identified by the key parameter.
Throws:
IllegalArgumentException - in case the "key" parameter is null

remove

public static void remove(String key)
                   throws IllegalArgumentException
Remove the 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.

Throws:
IllegalArgumentException - in case the "key" parameter is null

clear

public static void clear()
Clear all entries in the MDC of the underlying implementation.


getMDCAdapter

public static MDCAdapter getMDCAdapter()
Returns the MDCAdapter instance currently in use.

Returns:
the MDcAdapter instance currently in use.
Since:
1.4.2

SLF4J API
Version 1.4.3

Copyright © 2005-2008 QOS.ch. All Rights Reserved.