public final class Slf4jMDCLogConfigurator extends Object implements LogDiagnosticsConfigurator
MDC
based log configurator.
Configures log diagnostic context as String
key and values
pairs. Context is supposed to appear in logging traces by the means
supported by Log4j. Context is maintained on a per thread basis.
Thread switching (like running task in ThreadPoolExecutor
or newly created Thread
require explicit action in order to
transfer the context to the new thread and later clean it up.
MDC
Constructor and Description |
---|
Slf4jMDCLogConfigurator() |
Modifier and Type | Method and Description |
---|---|
void |
cleanUpContext()
Clean the logging context for the current thread.
|
void |
cleanUpContext(Collection<String> keys)
Cleans specified keys from the logging context.
|
void |
configureContext(Map<String,String> diagCtx)
Configure logging context for the current thread.
|
Map<String,String> |
getContext()
Retrieve the logging context for the current thread
(
Thread.currentThread() ). |
public void configureContext(Map<String,String> diagCtx)
LogDiagnosticsConfigurator
configureContext
in interface LogDiagnosticsConfigurator
diagCtx
- log diagnostics contextpublic void cleanUpContext()
LogDiagnosticsConfigurator
WARNING: this will clear the while underlying storage of the context, e.g. the slf4j MDC. It is possible that other data is stored in that storage, which is not supposed to be cleared. Use this method with caution, the vAPI infrastructure will never invoke it.
cleanUpContext
in interface LogDiagnosticsConfigurator
public void cleanUpContext(Collection<String> keys)
LogDiagnosticsConfigurator
cleanUpContext
in interface LogDiagnosticsConfigurator
keys
- the keys to be cleaned; must not be null
public Map<String,String> getContext()
LogDiagnosticsConfigurator
Thread.currentThread()
).
The result can be used to transfer the logging context to another thread, which continues the execution of the logical operation
getContext
in interface LogDiagnosticsConfigurator
Map
representing the log diagnostics contextCopyright © 2015. All Rights Reserved.