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. For java.util.logging which does not support MDC,
BasicMDCAdapter will be used. For other systems, i.e. slf4j-simple
and slf4j-nop, NOPMDCAdapter will be used.
Thus, as a SLF4J user, you can take advantage of MDC in the presence of log4j, logback, or java.util.logging, but without forcing these systems 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.
| Modifier and Type | Class and Description |
|---|---|
| public static class | MDC.
An adapter to remove the key when done. |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static MDCAdapter | |
| private static final String | |
| pack-priv static final String | |
| pack-priv static final String |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static void | |
| private static void | |
| public static String | |
| public static Map | Returns: A copy of the current thread's context map. May be null.Return a copy of the current thread's context map, with keys and values of type String. |
| public Deque | Returns: copy of stack referenced by 'key'. May be null.identifies the stack key)Returns a copy of the deque(stack) referenced by 'key'. |
| public static MDCAdapter | Returns: the MDcAdapter instance currently in use.Returns the MDCAdapter instance currently in use. |
| private static MDCAdapter | |
| public static String | |
| public static void | |
| public static void | |
| public static MDC. | Returns: aCloseable who can remove key when close
is called.non-null key key, String value to put in the map val)Put a diagnostic context value (the |
| public static void | |
| public static void | setContextMap(Map<String, String>
must contain only keys and values of type String contextMap)Set the current thread's context map by first clearing any existing map and then copying the map passed as parameter. |
| pack-priv static void |
| MDC_ADAPTER | back to summary |
|---|---|
| pack-priv static MDCAdapter MDC_ADAPTER | |
| MDC_APAPTER_CANNOT_BE_NULL_MESSAGE | back to summary |
|---|---|
| private static final String MDC_APAPTER_CANNOT_BE_NULL_MESSAGE | |
| NO_STATIC_MDC_BINDER_URL | back to summary |
|---|---|
| pack-priv static final String NO_STATIC_MDC_BINDER_URL | |
| NULL_MDCA_URL | back to summary |
|---|---|
| pack-priv static final String NULL_MDCA_URL | |
| MDC | back to summary |
|---|---|
| private MDC() | |
| clear | back to summary |
|---|---|
| public static void clear() Clear all entries in the MDC of the underlying implementation. | |
| emitTemporaryMDCAdapterWarningIfNeeded | back to summary |
|---|---|
| private static void emitTemporaryMDCAdapterWarningIfNeeded(SLF4JServiceProvider provider) | |
| get | back to summary |
|---|---|
| public static String get(String key) throws IllegalArgumentException Get the diagnostic context identified by the This method delegates all work to the MDC of the underlying logging system.
| |
| getCopyOfContextMap | back to summary |
|---|---|
| public static Map Return a copy of the current thread's context map, with keys and values of type String. Returned value may be null. | |
| getCopyOfDequeByKey | back to summary |
|---|---|
| public Deque Returns a copy of the deque(stack) referenced by 'key'. May be null. | |
| getMDCAdapter | back to summary |
|---|---|
| public static MDCAdapter getMDCAdapter() Returns the MDCAdapter instance currently in use.
Since 2.0.17, if the MDCAdapter instance is null, then this method set it to use
the adapter returned by the SLF4JProvider. However, in the vast majority of cases
the MDCAdapter will be set earlier (during initialization) by
| |
| getMDCAdapterGivenByProvider | back to summary |
|---|---|
| private static MDCAdapter getMDCAdapterGivenByProvider() | |
| popByKey | back to summary |
|---|---|
| public static String popByKey(String key) Pop the stack referenced by 'key' and return the value possibly null. | |
| pushByKey | back to summary |
|---|---|
| public static void pushByKey(String key, String value) Push a value into the deque(stack) referenced by 'key'. | |
| put | back to summary |
|---|---|
| public static void put(String key, String val) throws IllegalArgumentException Put a diagnostic context value (the This method delegates all work to the MDC of the underlying logging system.
| |
| putCloseable | back to summary |
|---|---|
| public static MDC. Put a diagnostic context value (the This method delegates all work to the MDC of the underlying logging system.
This method return a
Useful with Java 7 for example :
| |
| remove | back to summary |
|---|---|
| public static void remove(String key) throws IllegalArgumentException Remove the diagnostic context identified by the
| |
| setContextMap | back to summary |
|---|---|
| public static void setContextMap(Map<String, String> contextMap) Set the current thread's context map by first clearing any existing map and then copying the map passed as parameter. The context map passed as parameter must only contain keys and values of type String. Null valued argument is allowed (since SLF4J version 2.0.0). | |
| setMDCAdapter | back to summary |
|---|---|
| pack-priv static void setMDCAdapter(MDCAdapter anMDCAdapter) Set MDCAdapter instance to use.
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Implements java. Closes this stream and releases any system resources associated with it. |
| key | back to summary |
|---|---|
| private final String key | |
| MDCCloseable | back to summary |
|---|---|
| private MDCCloseable(String key) | |
| close | back to summary |
|---|---|
| public void close() Implements java. Doc from java. Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect. As noted in | |