From 368417be7cde9922ac897a979856a1b8204bc9e9 Mon Sep 17 00:00:00 2001 From: paladox Date: Mon, 13 Apr 2020 17:26:54 +0100 Subject: [PATCH 1/2] log4j2: Use setContextData not setContextMap Also update the documentation for mdcProperties --- .../common/flogger/backend/log4j2/Log4j2SimpleLogEvent.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/log4j2/src/main/java/com/google/common/flogger/backend/log4j2/Log4j2SimpleLogEvent.java b/log4j2/src/main/java/com/google/common/flogger/backend/log4j2/Log4j2SimpleLogEvent.java index 4f3d9935..e9e34666 100644 --- a/log4j2/src/main/java/com/google/common/flogger/backend/log4j2/Log4j2SimpleLogEvent.java +++ b/log4j2/src/main/java/com/google/common/flogger/backend/log4j2/Log4j2SimpleLogEvent.java @@ -84,9 +84,9 @@ LogEvent asLoggingEvent() { // are written from the current thread. // // Example: - // MDC.put("user.id", userId); + // ThreadContext.put("user.id", userId); // // do business logic that triggers logs - // MDC.clear(); + // ThreadContext.clear(); // // By using '%X{key}' in the ConversionPattern of an appender this data can be included in the // logs. @@ -112,7 +112,7 @@ LogEvent asLoggingEvent() { .setThrown(thrown != null ? Throwables.getRootCause(thrown) : null) .setIncludeLocation(true) .setSource(getLocationInfo()) - .setContextMap(mdcProperties) + .setContextData(mdcProperties) .build(); } From d376ac2132358daf7350e8a4447ecd77bda279fc Mon Sep 17 00:00:00 2001 From: paladox Date: Mon, 13 Apr 2020 17:34:45 +0100 Subject: [PATCH 2/2] Update Log4j2SimpleLogEvent.java --- .../common/flogger/backend/log4j2/Log4j2SimpleLogEvent.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/log4j2/src/main/java/com/google/common/flogger/backend/log4j2/Log4j2SimpleLogEvent.java b/log4j2/src/main/java/com/google/common/flogger/backend/log4j2/Log4j2SimpleLogEvent.java index e9e34666..c871b58f 100644 --- a/log4j2/src/main/java/com/google/common/flogger/backend/log4j2/Log4j2SimpleLogEvent.java +++ b/log4j2/src/main/java/com/google/common/flogger/backend/log4j2/Log4j2SimpleLogEvent.java @@ -28,6 +28,7 @@ import org.apache.logging.log4j.core.impl.Log4jLogEvent; import org.apache.logging.log4j.core.util.Throwables; import org.apache.logging.log4j.message.SimpleMessage; +import org.apache.logging.log4j.util.SortedArrayStringMap; /** Class that represents a log entry that can be written to log4j2. */ final class Log4j2SimpleLogEvent implements SimpleLogHandler { @@ -112,7 +113,7 @@ LogEvent asLoggingEvent() { .setThrown(thrown != null ? Throwables.getRootCause(thrown) : null) .setIncludeLocation(true) .setSource(getLocationInfo()) - .setContextData(mdcProperties) + .setContextData(new SortedArrayStringMap(mdcProperties)) .build(); }