@Test public void test() throws Exception { try (AutoCloseable ctx = diagnosticInfo.injectToContext(UUID.randomUUID().toString(), null)) { String object = MDC.get(DiagnosticInfo.REQUEST_UUID); System.out.println(DiagnosticInfo.REQUEST_UUID + ":\t" + object); Assert.assertNotNull(object); } }
public final AutoCloseable injectToContext(String requestUid, String description) { if (requestUid == null) { requestUid = uuidGenerator.generate(); } MDC.put(KEY_USER, getCurrentUser()); MDC.put(REQUEST_UUID, requestUid); return () -> { MDC.remove(KEY_USER); MDC.remove(REQUEST_UUID); }; }
DiagnosticInfo { public final AutoCloseable injectToContext(String requestUid, String description) { if (requestUid == null) { requestUid = uuidGenerator.generate(); } MDC.put(KEY_USER, getCurrentUser()); MDC.put(REQUEST_UUID, requestUid); return () -> { MDC.remove(KEY_USER); MDC.remove(REQUEST_UUID); }; } }
DiagnosticInfo { public final AutoCloseable injectToContext(String requestUid, String description) { if (requestUid == null) { requestUid = uuidGenerator.generate(); } MDC.put(KEY_USER, getCurrentUser()); MDC.put(REQUEST_UUID, requestUid); return () -> { MDC.remove(KEY_USER); MDC.remove(REQUEST_UUID); }; }  }
DiagnosticInfo { public final AutoCloseable injectToContext(String requestUid, String description) { if (requestUid == null) { requestUid = uuidGenerator.generate(); } MDC.put(KEY_USER, getCurrentUser()); MDC.put(REQUEST_UUID, requestUid); return () -> { MDC.remove(KEY_USER); MDC.remove(REQUEST_UUID); }; }  String getCurrentUser(); final AutoCloseable injectToContext(String requestUid, String description); }
DiagnosticInfo { public final AutoCloseable injectToContext(String requestUid, String description) { if (requestUid == null) { requestUid = uuidGenerator.generate(); } MDC.put(KEY_USER, getCurrentUser()); MDC.put(REQUEST_UUID, requestUid); return () -> { MDC.remove(KEY_USER); MDC.remove(REQUEST_UUID); }; }  String getCurrentUser(); final AutoCloseable injectToContext(String requestUid, String description); static final String KEY_USER; static final String REQUEST_UUID; }