From 42e0355d1c2e95e3f03b98ed6ffe7594ccd8c74f Mon Sep 17 00:00:00 2001 From: Ceki Gulcu Date: Sun, 23 Jul 2023 11:33:41 +0200 Subject: [PATCH] Change LoggerContet to use MDCAdapter instead of LogbackMDCAdapter , partial fix for LOGBACK-1756 Signed-off-by: Ceki Gulcu --- .../main/java/ch/qos/logback/classic/LoggerContext.java | 9 +++++---- .../java/ch/qos/logback/classic/spi/ILoggingEvent.java | 3 ++- .../java/ch/qos/logback/classic/spi/LoggingEvent.java | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java b/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java index e86758a91a..8875099889 100755 --- a/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java @@ -44,6 +44,7 @@ import ch.qos.logback.core.status.StatusListener; import ch.qos.logback.core.status.StatusManager; import ch.qos.logback.core.status.WarnStatus; +import org.slf4j.spi.MDCAdapter; /** * LoggerContext glues many of the logback-classic components together. In @@ -71,7 +72,7 @@ public class LoggerContext extends ContextBase implements ILoggerFactory, LifeCy private boolean packagingDataEnabled = DEFAULT_PACKAGING_DATA; SequenceNumberGenerator sequenceNumberGenerator = null; // by default there is no SequenceNumberGenerator - LogbackMDCAdapter mdcAdapter; + MDCAdapter mdcAdapter; private int maxCallerDataDepth = ClassicConstants.DEFAULT_MAX_CALLEDER_DATA_DEPTH; @@ -405,16 +406,16 @@ public SequenceNumberGenerator getSequenceNumberGenerator() { return sequenceNumberGenerator; } - public LogbackMDCAdapter getMDCAdapter() { + public MDCAdapter getMDCAdapter() { return mdcAdapter; } - public void setMDCAdapter(LogbackMDCAdapter anAdapter) { + public void setMDCAdapter(MDCAdapter anAdapter) { if(this.mdcAdapter == null) { this.mdcAdapter = anAdapter; } else { StatusManager sm = getStatusManager(); - sm.add(new ErrorStatus("mdcAdapter already set", this, new Throwable())); + sm.add(new ErrorStatus("mdcAdapter cannot be set multiple times", this, new IllegalStateException("mdcAdapter already set"))); } } } diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java index 686fb212b8..f8ea5b93eb 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java @@ -137,7 +137,8 @@ default Marker getMarker() { /** * Return the {@link java.time.Instant Instant} the event was created. * - * Default implementation returns null. + * Default implementation returns the instant corresponding to the value returned by @link + * {@link #getTimeStamp()}. * * @return the {@link java.time.Instant Instant} the event was created. * @since 1.3 diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java index ba726bd63c..77dc2cff7f 100755 --- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java @@ -404,7 +404,7 @@ public String getFormattedMessage() { public Map getMDCPropertyMap() { // populate mdcPropertyMap if null if (mdcPropertyMap == null) { - LogbackMDCAdapter mdcAdapter = loggerContext.getMDCAdapter(); + MDCAdapter mdcAdapter = loggerContext.getMDCAdapter(); if (mdcAdapter instanceof LogbackMDCAdapter) mdcPropertyMap = ((LogbackMDCAdapter) mdcAdapter).getPropertyMap(); else