Top Description Fields Constructors Methods
org.slf4j.helpers

public Class BasicMDCAdapter

extends Object
implements MDCAdapter
Class Inheritance
All Implemented Interfaces
org.slf4j.spi.MDCAdapter
Imports
org.slf4j.spi.MDCAdapter, java.util.*

Basic MDC implementation, which can be used with logging systems that lack out-of-the-box MDC support. This code was initially inspired by logback's LogbackMDCAdapter. However, LogbackMDCAdapter has evolved and is now considerably more sophisticated.
Authors
Ceki Gulcu, Maarten Bosteels, Lukasz Cwik
Since
1.5.0

Field Summary

Modifier and TypeField and Description
private final InheritableThreadLocal<Map<String, String>>
private final ThreadLocalMapOfStacks

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Implements org.slf4j.spi.MDCAdapter.clear.

Clear all entries in the MDC.

public void
clearDequeByKey(String key)

Implements org.slf4j.spi.MDCAdapter.clearDequeByKey.

Clear the deque(stack) referenced by 'key'.

public String
get(String key)

Implements org.slf4j.spi.MDCAdapter.get.

Get the context identified by the key parameter.

public Map<String, String>
getCopyOfContextMap()

Implements org.slf4j.spi.MDCAdapter.getCopyOfContextMap.

Return a copy of the current thread's context map.

public Deque<String>
getCopyOfDequeByKey(String key)

Implements org.slf4j.spi.MDCAdapter.getCopyOfDequeByKey.

Returns a copy of the deque(stack) referenced by 'key'.

public Set<String>

Returns:

the keys in the MDC
getKeys
()

Returns the keys in the MDC as a Set of Strings The returned value can be null.

public String
popByKey(String key)

Implements org.slf4j.spi.MDCAdapter.popByKey.

Pop the stack referenced by 'key' and return the value possibly null.

public void
pushByKey(String key, String value)

Implements org.slf4j.spi.MDCAdapter.pushByKey.

Push a value into the deque(stack) referenced by 'key'.

public void
put(String key, String val)

Implements org.slf4j.spi.MDCAdapter.put.

Put a context value (the val parameter) as identified with the key parameter into the current thread's context map.

public void
remove(String key)

Implements org.slf4j.spi.MDCAdapter.remove.

Remove the context identified by the key parameter.

public void
setContextMap(Map<String, String> contextMap)

Implements org.slf4j.spi.MDCAdapter.setContextMap.

Set the current thread's context map by first clearing any existing map and then copying the map passed as parameter.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

inheritableThreadLocalMapback to summary
private final InheritableThreadLocal<Map<String, String>> inheritableThreadLocalMap
threadLocalMapOfDequesback to summary
private final ThreadLocalMapOfStacks threadLocalMapOfDeques

Constructor Detail

BasicMDCAdapterback to summary
public BasicMDCAdapter()

Method Detail

clearback to summary
public void clear()

Implements org.slf4j.spi.MDCAdapter.clear.

Clear all entries in the MDC.

clearDequeByKeyback to summary
public void clearDequeByKey(String key)

Implements org.slf4j.spi.MDCAdapter.clearDequeByKey.

Doc from org.slf4j.spi.MDCAdapter.clearDequeByKey.

Clear the deque(stack) referenced by 'key'.

Annotations
@Override
getback to summary
public String get(String key)

Implements org.slf4j.spi.MDCAdapter.get.

Get the context identified by the key parameter.

getCopyOfContextMapback to summary
public Map<String, String> getCopyOfContextMap()

Implements org.slf4j.spi.MDCAdapter.getCopyOfContextMap.

Return a copy of the current thread's context map. Returned value may be null.

getCopyOfDequeByKeyback to summary
public Deque<String> getCopyOfDequeByKey(String key)

Implements org.slf4j.spi.MDCAdapter.getCopyOfDequeByKey.

Doc from org.slf4j.spi.MDCAdapter.getCopyOfDequeByKey.

Returns a copy of the deque(stack) referenced by 'key'. May be null.

Annotations
@Override
getKeysback to summary
public Set<String> getKeys()

Returns the keys in the MDC as a Set of Strings The returned value can be null.

Returns:Set<String>

the keys in the MDC

popByKeyback to summary
public String popByKey(String key)

Implements org.slf4j.spi.MDCAdapter.popByKey.

Doc from org.slf4j.spi.MDCAdapter.popByKey.

Pop the stack referenced by 'key' and return the value possibly null.

Annotations
@Override
pushByKeyback to summary
public void pushByKey(String key, String value)

Implements org.slf4j.spi.MDCAdapter.pushByKey.

Doc from org.slf4j.spi.MDCAdapter.pushByKey.

Push a value into the deque(stack) referenced by 'key'.

Annotations
@Override
putback to summary
public void put(String key, String val)

Implements org.slf4j.spi.MDCAdapter.put.

Put a context value (the val parameter) as identified with the key parameter into the current thread's context map. Note that contrary to log4j, the val parameter can be null.

If the current thread does not have a context map it is created as a side effect of this call.

Exceptions
IllegalArgumentException:
in case the "key" parameter is null
removeback to summary
public void remove(String key)

Implements org.slf4j.spi.MDCAdapter.remove.

Remove the context identified by the key parameter.

setContextMapback to summary
public void setContextMap(Map<String, String> contextMap)

Implements org.slf4j.spi.MDCAdapter.setContextMap.

Doc from org.slf4j.spi.MDCAdapter.setContextMap.

Set the current thread's context map by first clearing any existing map and then copying the map passed as parameter. The context map parameter must only contain keys and values of type String. Implementations must support null valued map passed as parameter.