public class CloseableThreadContext
extends java.lang.Object
stack or map and them removes them when the object is closed, e.g. as part
of a try-with-resources. User code can now look like this:
try (final CloseableThreadContext.Instance ignored = CloseableThreadContext.put(key1, value1).put(key2, value2)) {
callSomeMethodThatLogsALot();
// Entries for key1 and key2 are automatically removed from the ThreadContext map when done.
}
| Modifier and Type | Class and Description |
|---|---|
static class |
CloseableThreadContext.Instance |
| Modifier | Constructor and Description |
|---|---|
private |
CloseableThreadContext() |
| Modifier and Type | Method and Description |
|---|---|
static CloseableThreadContext.Instance |
push(java.lang.String message)
Pushes new diagnostic context information on to the Thread Context Stack.
|
static CloseableThreadContext.Instance |
push(java.lang.String message,
java.lang.Object... args)
Pushes new diagnostic context information on to the Thread Context Stack.
|
static CloseableThreadContext.Instance |
pushAll(java.util.List<java.lang.String> messages)
Populates the Thread Context Stack with the supplied stack.
|
static CloseableThreadContext.Instance |
put(java.lang.String key,
java.lang.String value)
Populates the Thread Context Map with the supplied key/value pair.
|
static CloseableThreadContext.Instance |
putAll(java.util.Map<java.lang.String,java.lang.String> values)
Populates the Thread Context Map with the supplied key/value pairs.
|
public static CloseableThreadContext.Instance push(java.lang.String message)
message - The new diagnostic context information.public static CloseableThreadContext.Instance push(java.lang.String message, java.lang.Object... args)
message - The new diagnostic context information.args - Parameters for the message.public static CloseableThreadContext.Instance put(java.lang.String key, java.lang.String value)
ThreadContext will be replaced with the supplied value, and restored back to their original value when
the instance is closed.key - The key to be addedvalue - The value to be addedpublic static CloseableThreadContext.Instance pushAll(java.util.List<java.lang.String> messages)
messages - The list of messages to be addedpublic static CloseableThreadContext.Instance putAll(java.util.Map<java.lang.String,java.lang.String> values)
ThreadContext will be replaced with the supplied values, and restored back to their original value when
the instance is closed.values - The map of key/value pairs to be added