Class MDC

java.lang.Object
com.codename1.backend.log.MDC

public final class MDC extends Object

A per-thread context map appended to every line logged on that thread, as slf4j's MDC is: put a request id once and every line of that request carries it.

MDC.put("request", requestId);
try {
    handle(request);
} finally {
    MDC.remove("request");
}

The map belongs to the thread, a virtual thread included, so a value put by one request is never seen by another. Remove what you put: a pooled thread otherwise carries it into the next request it serves.

  • Method Details

    • put

      public static void put(String key, String value)
      Sets key for every line this thread logs from now on; a null value removes it.
    • get

      public static String get(String key)
      The value this thread set for key, or null.
    • remove

      public static void remove(String key)
      Removes key from this thread's context.
    • clear

      public static void clear()
      Empties this thread's context.