Package org.apache.logging.log4j
Class CloseableThreadContext.Instance
- java.lang.Object
-
- org.apache.logging.log4j.CloseableThreadContext.Instance
-
- All Implemented Interfaces:
java.lang.AutoCloseable
- Enclosing class:
- CloseableThreadContext
public static class CloseableThreadContext.Instance extends java.lang.Object implements java.lang.AutoCloseable
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Removes the values from theThreadContext
.CloseableThreadContext.Instance
push(java.lang.String message)
Pushes new diagnostic context information on to the Thread Context Stack.CloseableThreadContext.Instance
push(java.lang.String message, java.lang.Object[] args)
Pushes new diagnostic context information on to the Thread Context Stack.CloseableThreadContext.Instance
pushAll(java.util.List<java.lang.String> messages)
Populates the Thread Context Stack with the supplied stack.CloseableThreadContext.Instance
put(java.lang.String key, java.lang.String value)
Populates the Thread Context Map with the supplied key/value pair.CloseableThreadContext.Instance
putAll(java.util.Map<java.lang.String,java.lang.String> values)
Populates the Thread Context Map with the supplied key/value pairs.
-
-
-
Method Detail
-
push
public CloseableThreadContext.Instance push(java.lang.String message)
Pushes new diagnostic context information on to the Thread Context Stack. The information will be popped off when the instance is closed.- Parameters:
message
- The new diagnostic context information.- Returns:
- the instance that will back out the changes when closed.
-
push
public CloseableThreadContext.Instance push(java.lang.String message, java.lang.Object[] args)
Pushes new diagnostic context information on to the Thread Context Stack. The information will be popped off when the instance is closed.- Parameters:
message
- The new diagnostic context information.args
- Parameters for the message.- Returns:
- the instance that will back out the changes when closed.
-
put
public CloseableThreadContext.Instance put(java.lang.String key, java.lang.String value)
Populates the Thread Context Map with the supplied key/value pair. Any existing key in theThreadContext
will be replaced with the supplied value, and restored back to their original value when the instance is closed.- Parameters:
key
- The key to be addedvalue
- The value to be added- Returns:
- a new instance that will back out the changes when closed.
-
putAll
public CloseableThreadContext.Instance putAll(java.util.Map<java.lang.String,java.lang.String> values)
Populates the Thread Context Map with the supplied key/value pairs. Any existing keys in theThreadContext
will be replaced with the supplied values, and restored back to their original value when the instance is closed.- Parameters:
values
- The map of key/value pairs to be added- Returns:
- a new instance that will back out the changes when closed.
- Since:
- 2.8
-
pushAll
public CloseableThreadContext.Instance pushAll(java.util.List<java.lang.String> messages)
Populates the Thread Context Stack with the supplied stack. The information will be popped off when the instance is closed.- Parameters:
messages
- The list of messages to be added- Returns:
- a new instance that will back out the changes when closed.
- Since:
- 2.8
-
close
public void close()
Removes the values from theThreadContext
.Values pushed to the
ThreadContext
stack will be popped off.Values put on the
ThreadContext
map will be removed, or restored to their original values it they already existed.- Specified by:
close
in interfacejava.lang.AutoCloseable
-
-