Skip to content

Instantly share code, notes, and snippets.

@stdmitry
Last active April 23, 2022 17:53
Show Gist options
  • Save stdmitry/21b16c75f0d9291a26fe932ffbc099eb to your computer and use it in GitHub Desktop.
Save stdmitry/21b16c75f0d9291a26fe932ffbc099eb to your computer and use it in GitHub Desktop.
Java logging
public class LogHelper {
public static <T> Consumer<Signal<T>> info(Logger logger, String logStatement, Object... arguments) {
return signal -> {
if (signal.isOnNext()) {
info(logger, logStatement, signal.getContextView(), arguments);
}
};
}
public static void info(Logger logger,String logStatement, ContextView ctx, Object... arguments) {
var requestId = (String) ctx.get("requestId");
try (MDC.MDCCloseable ignored = MDC.putCloseable("requestId", requestId)) {
logger.info(logStatement, arguments);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment