Class CloseableThreadContext.Instance

java.lang.Object
org.apache.logging.log4j.CloseableThreadContext.Instance
All Implemented Interfaces:
AutoCloseable
Enclosing class:
CloseableThreadContext

public static class CloseableThreadContext.Instance extends Object implements AutoCloseable
  • Method Details

    • push

      public CloseableThreadContext.Instance push(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(String message, 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(String key, String value)
      Populates the Thread Context Map with the supplied key/value pair. Any existing key in the ThreadContext 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 added
      value - The value to be added
      Returns:
      a new instance that will back out the changes when closed.
    • putAll

      Populates the Thread Context Map with the supplied key/value pairs. Any existing keys in the ThreadContext 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(List<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 the ThreadContext.

      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 interface AutoCloseable