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

public Class LogbackMDCAdapterSimple

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

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

Author
Ceki Gülcü

Field Summary

Modifier and TypeField and Description
private final ThreadLocalMapOfStacks
pack-priv final ThreadLocal<Map<String, String>>

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'.
private Map<String, String>
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
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<String, String>
the new map
contextMap
)

Implements org.slf4j.spi.MDCAdapter.setContextMap.

Set the MDC map to the map passed as parameter.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

threadLocalMapOfDequesback to summary
private final ThreadLocalMapOfStacks threadLocalMapOfDeques
threadLocalUnmodifiableMapback to summary
pack-priv final ThreadLocal<Map<String, String>> threadLocalUnmodifiableMap

Constructor Detail

LogbackMDCAdapterSimpleback to summary
public LogbackMDCAdapterSimple()

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'.

Parameters
key:String

identifies the stack

Annotations
@Override
duplicateMapback to summary
private Map<String, String> duplicateMap(Map<String, String> oldMap)
getback to summary
public String get(String key)

Implements org.slf4j.spi.MDCAdapter.get.

Get the context identified by the key parameter.

Returns:String

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

the string value 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.

Returns:Map<String, String>

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.

makeUnmodifiableAndThreadLocalSetback to summary
private void makeUnmodifiableAndThreadLocalSet(Map<String, String> aMap)
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.

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.

Set the MDC map to the map passed as parameter.

Parameters
contextMap:Map<String, String>

the new map