Package org.apache.solr.logging
Class MDCSnapshot
- java.lang.Object
-
- org.apache.solr.logging.MDCSnapshot
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public final class MDCSnapshot extends Object implements Closeable
Takes a 'snapshot' of the current MDC context map which is restored on (auto) close. This can be used to ensure that no MDC values set (or overridden) inside of call stack will "leak" beyond that call stack.try (var mdcSnapshot = MDCSnapshot.create()) { assert null != mdcSnapshot; // prevent compiler warning // ... arbitrary calls to MDC methods }
- See Also:
MDC.putCloseable(java.lang.String, java.lang.String)
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
static MDCSnapshot
create()
-
-
-
Method Detail
-
create
public static MDCSnapshot create()
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-