public class CloseableThreadContext extends 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 | Description |
|---|---|---|
static class |
CloseableThreadContext.Instance |
| Modifier and Type | Method | Description |
|---|---|---|
static CloseableThreadContext.Instance |
push(String message) |
Pushes new diagnostic context information on to the Thread Context Stack.
|
static CloseableThreadContext.Instance |
push(String message,
Object... args) |
Pushes new diagnostic context information on to the Thread Context Stack.
|
static CloseableThreadContext.Instance |
pushAll(List<String> messages) |
Populates the Thread Context Stack with the supplied stack.
|
static CloseableThreadContext.Instance |
put(String key,
String value) |
Populates the Thread Context Map with the supplied key/value pair.
|
static CloseableThreadContext.Instance |
putAll(Map<String,String> values) |
Populates the Thread Context Map with the supplied key/value pairs.
|
public static CloseableThreadContext.Instance push(String message)
message - The new diagnostic context information.public static CloseableThreadContext.Instance push(String message, Object... args)
message - The new diagnostic context information.args - Parameters for the message.public static CloseableThreadContext.Instance put(String key, 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(List<String> messages)
messages - The list of messages to be addedpublic static CloseableThreadContext.Instance putAll(Map<String,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 addedCopyright © 1999-2018. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.