Class HelidonMdc

java.lang.Object
io.helidon.logging.common.HelidonMdc

public class HelidonMdc extends Object
Helidon MDC delegates values across all of the supported logging frameworks on the classpath.

Helidon permits adding MDC entries using Supplier<String> values as well as direct String values. Although some logging implementations provide their own context maps (for example ThreadContext in Log4J and MDC in SLF4J), they map MDC keys to String values, not to arbitrary objects that would accommodate Supplier<String>. Therefore, Helidon not only propagates every set operation to the loaded MDC providers, but also manages its own map of key/supplier pairs. Helidon resolves each lookup using that map if possible, delegating a look-up to the loaded MDC providers only if there is no supplier for a key.

  • Method Details

    • set

      public static void set(String key, String value)
      Propagate value to all of the MdcProvider registered via SPI.
      Parameters:
      key - entry key
      value - entry value
    • set

      public static void set(String key, Supplier<String> valueSupplier)
      Propagate the value supplier to all MdcProvider instances registered.
      Parameters:
      key - entry key
      valueSupplier - supplier of the entry value
    • setDeferred

      public static void setDeferred(String key, Supplier<String> valueSupplier)
      Sets a value supplier without immediately getting the value and propagating the value to underlying logging implementations.

      Normally, user code should use set(String, java.util.function.Supplier) instead.

      Parameters:
      key - entry key
      valueSupplier - supplier of the entry value
    • remove

      public static void remove(String key)
      Remove value with the specific key from all of the instances of MdcProvider.
      Parameters:
      key - key
    • clear

      public static void clear()
      Remove all of the entries bound to the current thread from the instances of MdcProvider.
    • get

      public static Optional<String> get(String key)
      Return the first value found to the specific key.
      Parameters:
      key - key
      Returns:
      found value bound to key