org.apache.logging.log4j

Class CloseableThreadContext.Instance

    • Method Detail

      • 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

        public CloseableThreadContext.Instance putAll(Map<String,String> values)
        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

Copyright © 1999-2023 The Apache Software Foundation. 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.