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.MDCAdapter
put
in class org.slf4j.helpers.BasicMDCAdapter
public String get(String key)
get
in interface org.slf4j.spi.MDCAdapter
get
in class org.slf4j.helpers.BasicMDCAdapter
public void remove(String key)
remove
in interface org.slf4j.spi.MDCAdapter
remove
in class org.slf4j.helpers.BasicMDCAdapter
public void clear()
clear
in interface org.slf4j.spi.MDCAdapter
clear
in class org.slf4j.helpers.BasicMDCAdapter
public Map<String,String> getCopyOfContextMap()
null
is returned if
setEnable
, or
setReturnNullCopyWhenMdcNotSet
,
and put
has not been called.
getCopyOfContextMap
in interface org.slf4j.spi.MDCAdapter
getCopyOfContextMap
in class org.slf4j.helpers.BasicMDCAdapter
public void setContextMap(Map<String,String> contextMap)
setContextMap
in interface org.slf4j.spi.MDCAdapter
setContextMap
in class org.slf4j.helpers.BasicMDCAdapter
public 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 © 2023. All rights reserved.