Top Description Fields Constructors Methods
ch.qos.logback.classic.util

public Class LogbackMDCAdapter

extends Object
implements MDCAdapter
Class Inheritance
All Implemented Interfaces
org.slf4j.spi.MDCAdapter
Imports
org.slf4j.helpers.ThreadLocalMapOfStacks, org.slf4j.spi.MDCAdapter, java.util.Collections, .Deque, .HashMap, .Map, .Set

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. Note that a child thread does not inherit the mapped diagnostic context of its parent.

For more information about MDC, please refer to the online manual at http://logback.qos.ch/manual/mdc.html

Authors
Ceki Gülcü, Michael Franz

Field Summary

Modifier and TypeField and Description
pack-priv final ThreadLocal<Map<String, String>>
pack-priv final ThreadLocal<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
identifies the stack
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<K, V>
getCopyOfContextMap()

Implements org.slf4j.spi.MDCAdapter.getCopyOfContextMap.

Return a copy of the current thread's context map.
public Deque<String>
getCopyOfDequeByKey(String
identifies the stack
key
)

Implements org.slf4j.spi.MDCAdapter.getCopyOfDequeByKey.

Returns a copy of the deque(stack) referenced by 'key'.
public Set<String>
getKeys()

Returns the keys in the MDC as a Set.

public Map<String, String>
getPropertyMap()

Get the current thread's MDC as a map.

private void
public String
popByKey(String
identifies the deque(stack)
key
)

Implements org.slf4j.spi.MDCAdapter.popByKey.

Pop the stack referenced by 'key' and return the value possibly null.
public void
pushByKey(String
identifies the appropriate stack
key
,
String
the value to push into the stack
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<K, V>
must contain only keys and values of type 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

readOnlyThreadLocalMapback to summary
pack-priv final ThreadLocal<Map<String, String>> readOnlyThreadLocalMap
readWriteThreadLocalMapback to summary
pack-priv final ThreadLocal<Map<String, String>> readWriteThreadLocalMap
threadLocalMapOfDequesback to summary
private final ThreadLocalMapOfStacks threadLocalMapOfDeques

Constructor Detail

LogbackMDCAdapterback to summary
public LogbackMDCAdapter()

Method Detail

clearback to summary
public void clear()

Implements org.slf4j.spi.MDCAdapter.clear.

Clear all entries in the MDC.

Annotations
@Override
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'.

Parameters
key:String

identifies the stack

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

Implements org.slf4j.spi.MDCAdapter.get.

Get the context identified by the key parameter.

This method has no side effects.

Returns:String

Doc from org.slf4j.spi.MDCAdapter.get.

the string value identified by the key parameter.

Annotations
@Override
getCopyOfContextMapback to summary
public Map<K, V> getCopyOfContextMap()

Implements org.slf4j.spi.MDCAdapter.getCopyOfContextMap.

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

Returns:Map<K, V>

Doc from org.slf4j.spi.MDCAdapter.getCopyOfContextMap.

A copy of the current thread's context map. 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.

Parameters
key:String

identifies the stack

Returns:Deque<String>

copy of 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. The returned value can be null.

getPropertyMapback to summary
public Map<String, String> getPropertyMap()

Get the current thread's MDC as a map. This method is intended to be used internally.

The returned map is unmodifiable (since version 1.3.2/1.4.2).
Annotations
@SuppressWarnings:unchecked
nullifyReadOnlyThreadLocalMapback to summary
private void nullifyReadOnlyThreadLocalMap()
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.

Parameters
key:String

identifies the deque(stack)

Returns:String

the value just popped. May be 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'.

Parameters
key:String

identifies the appropriate stack

value:String

the value to push into the stack

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

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.

Each time a value is added, a new instance of the map is created. This is to be certain that the serialization process will operate on the updated map and not send a reference to the old map, thus not allowing the remote logback component to see the latest changes.

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.

Annotations
@Override
setContextMapback to summary
public void setContextMap(Map<K, V> 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.

Parameters
contextMap:Map<K, V>

must contain only keys and values of type String

Annotations
@SuppressWarnings:unchecked