public static void doLog(@NotNull String action,
@Nullable String image,
@Nullable String containerId,
@NotNull DockerCmd<?> cmd,
@Nullable Exception e) {
if (! log.isTraceEnabled()) {
return;
}
MDC.put(MDC_PREFIX + ".Action", nullToEmpty(action));
MDC.put(MDC_PREFIX + ".Image", nullToEmpty(image));
MDC.put(MDC_PREFIX + ".ContainerId", nullToEmpty(containerId));
try {
MDC.put(MDC_PREFIX + ".Command", objectMapper.writeValueAsString(cmd));
} catch (JsonProcessingException ignored) {
}
if (e != null) {
MDC.put(MDC_PREFIX + ".Exception", e.getLocalizedMessage());
log.trace("{} action with image: {}, containerId: {}", action, image, containerId, e);
} else {
log.trace("{} action with image: {}, containerId: {}", action, image, containerId);
}
MDC.remove(MDC_PREFIX + ".Action");
MDC.remove(MDC_PREFIX + ".Image");
MDC.remove(MDC_PREFIX + ".ContainerId");
MDC.remove(MDC_PREFIX + ".Command");
MDC.remove(MDC_PREFIX + ".Exception");
}