public class TestMDCAdapter
extends org.slf4j.helpers.BasicMDCAdapter
| Constructor and Description |
|---|
TestMDCAdapter() |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
String |
get(String key) |
boolean |
getAllowNullValues()
Whether null values are allowed in the MDC.
|
Map<String,String> |
getCopyOfContextMap()
Return a copy of the current thread's context map.
|
boolean |
getEnable()
Whether the MDC functionality is enabled.
|
boolean |
getInherit()
Whether child threads inherit a copy of the MDC from its parent thread.
|
static TestMDCAdapter |
getInstance()
Access the current MDC adapter.
|
boolean |
getReturnNullCopyWhenMdcNotSet()
Whether
getCopyOfContextMap() returns null when no values have been set. |
void |
put(String key,
String val) |
void |
remove(String key) |
void |
restoreOptions()
Reset the options to values defined by the static configuration.
|
void |
setAllowNullValues(boolean allowNullValues)
Define whether null values are allowed in the MDC.
|
void |
setContextMap(Map<String,String> contextMap) |
void |
setEnable(boolean enable)
Enable the MDC functionality for all threads.
|
void |
setInherit(boolean inherit)
Define whether child threads inherit a copy of the MDC from its parent thread.
|
void |
setReturnNullCopyWhenMdcNotSet(boolean returnNullCopyWhenMdcNotSet)
Define whether
getCopyOfContextMap() returns null when no values have been set. |
public void put(String key, String val)
put in interface org.slf4j.spi.MDCAdapterput in class org.slf4j.helpers.BasicMDCAdapterpublic String get(String key)
get in interface org.slf4j.spi.MDCAdapterget in class org.slf4j.helpers.BasicMDCAdapterpublic void remove(String key)
remove in interface org.slf4j.spi.MDCAdapterremove in class org.slf4j.helpers.BasicMDCAdapterpublic void clear()
clear in interface org.slf4j.spi.MDCAdapterclear in class org.slf4j.helpers.BasicMDCAdapterpublic Map<String,String> getCopyOfContextMap()
null is returned if
setEnable, or
setReturnNullCopyWhenMdcNotSet,
and put has not been called.
getCopyOfContextMap in interface org.slf4j.spi.MDCAdaptergetCopyOfContextMap in class org.slf4j.helpers.BasicMDCAdapterpublic void setContextMap(Map<String,String> contextMap)
setContextMap in interface org.slf4j.spi.MDCAdaptersetContextMap in class org.slf4j.helpers.BasicMDCAdapterpublic void setEnable(boolean enable)
enable - Whether to enable the MDC functionality. The default value is true.public void setInherit(boolean inherit)
Thread is constructed. This affects all threads.inherit - Whether to enable inheritance. The default value is false.public void setAllowNullValues(boolean allowNullValues)
allowNullValues - Whether to allow nulls. The default value is true.public void setReturnNullCopyWhenMdcNotSet(boolean returnNullCopyWhenMdcNotSet)
getCopyOfContextMap() returns null when no values have been set.
This affects all threads.returnNullCopyWhenMdcNotSet - Whether to return null. The default value is false.
If false, an empty map is returned instead.public boolean getEnable()
public boolean getInherit()
public boolean getAllowNullValues()
public boolean getReturnNullCopyWhenMdcNotSet()
getCopyOfContextMap() returns null when no values have been set.public void restoreOptions()
setEnable(boolean), setInherit(boolean), setAllowNullValues(boolean), and setReturnNullCopyWhenMdcNotSet(boolean).public static TestMDCAdapter getInstance()
Copyright © 2025. All rights reserved.