Skip to content

Commit 9c31880

Browse files
committed
Change LoggerContet to use MDCAdapter instead of LogbackMDCAdapter , partial fix for LOGBACK-1756
Signed-off-by: Ceki Gulcu <[email protected]>
1 parent 5ceb7c5 commit 9c31880

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import ch.qos.logback.core.status.StatusListener;
4545
import ch.qos.logback.core.status.StatusManager;
4646
import ch.qos.logback.core.status.WarnStatus;
47+
import org.slf4j.spi.MDCAdapter;
4748

4849
/**
4950
* LoggerContext glues many of the logback-classic components together. In
@@ -71,7 +72,7 @@ public class LoggerContext extends ContextBase implements ILoggerFactory, LifeCy
7172
private boolean packagingDataEnabled = DEFAULT_PACKAGING_DATA;
7273
SequenceNumberGenerator sequenceNumberGenerator = null; // by default there is no SequenceNumberGenerator
7374

74-
LogbackMDCAdapter mdcAdapter;
75+
MDCAdapter mdcAdapter;
7576

7677

7778
private int maxCallerDataDepth = ClassicConstants.DEFAULT_MAX_CALLEDER_DATA_DEPTH;
@@ -405,16 +406,16 @@ public SequenceNumberGenerator getSequenceNumberGenerator() {
405406
return sequenceNumberGenerator;
406407
}
407408

408-
public LogbackMDCAdapter getMDCAdapter() {
409+
public MDCAdapter getMDCAdapter() {
409410
return mdcAdapter;
410411
}
411412

412-
public void setMDCAdapter(LogbackMDCAdapter anAdapter) {
413+
public void setMDCAdapter(MDCAdapter anAdapter) {
413414
if(this.mdcAdapter == null) {
414415
this.mdcAdapter = anAdapter;
415416
} else {
416417
StatusManager sm = getStatusManager();
417-
sm.add(new ErrorStatus("mdcAdapter already set", this, new Throwable()));
418+
sm.add(new ErrorStatus("mdcAdapter cannot be set multiple times", this, new IllegalStateException("mdcAdapter already set")));
418419
}
419420
}
420421
}

logback-classic/src/main/java/ch/qos/logback/classic/spi/ILoggingEvent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ default Marker getMarker() {
137137
/**
138138
* Return the {@link java.time.Instant Instant} the event was created.
139139
*
140-
* Default implementation returns null.
140+
* Default implementation returns the instant corresponding to the value returned by @link
141+
* {@link #getTimeStamp()}.
141142
*
142143
* @return the {@link java.time.Instant Instant} the event was created.
143144
* @since 1.3

logback-classic/src/main/java/ch/qos/logback/classic/spi/LoggingEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ public String getFormattedMessage() {
404404
public Map<String, String> getMDCPropertyMap() {
405405
// populate mdcPropertyMap if null
406406
if (mdcPropertyMap == null) {
407-
LogbackMDCAdapter mdcAdapter = loggerContext.getMDCAdapter();
407+
MDCAdapter mdcAdapter = loggerContext.getMDCAdapter();
408408
if (mdcAdapter instanceof LogbackMDCAdapter)
409409
mdcPropertyMap = ((LogbackMDCAdapter) mdcAdapter).getPropertyMap();
410410
else

0 commit comments

Comments
 (0)