Class ThreadLocalLogContextSelector

  • All Implemented Interfaces:
    LogContextSelector

    public final class ThreadLocalLogContextSelector
    extends java.lang.Object
    implements LogContextSelector
    A log context selector which stores the chosen log context in a thread-local.
    • Field Detail

      • securityKey

        private final java.lang.Object securityKey
      • context

        private final java.lang.ThreadLocal<LogContext> context
    • Constructor Detail

      • ThreadLocalLogContextSelector

        public ThreadLocalLogContextSelector​(LogContextSelector delegate)
        Construct a new instance.
        Parameters:
        delegate - the selector to delegate to if no context is chosen
      • ThreadLocalLogContextSelector

        public ThreadLocalLogContextSelector​(java.lang.Object securityKey,
                                             LogContextSelector delegate)
        Construct a new instance.
        Parameters:
        securityKey - the security key required to push or pop a log context.
        delegate - the selector to delegate to if no context is chosen
    • Method Detail

      • getAndSet

        public LogContext getAndSet​(java.lang.Object securityKey,
                                    LogContext newValue)
        Get and set the log context.
        Parameters:
        securityKey - the security key to check (ignored if none was set on construction)
        newValue - the new log context value, or null to clear
        Returns:
        the previous log context value, or null if none was set