Skip to content

Commit

Permalink
Change LoggerContet to use MDCAdapter instead of LogbackMDCAdapter , …
Browse files Browse the repository at this point in the history
…partial fix for LOGBACK-1756

Signed-off-by: Ceki Gulcu <ceki@qos.ch>
  • Loading branch information
ceki committed Jul 23, 2023
1 parent 5ceb7c5 commit 9c31880
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public String getFormattedMessage() {
public Map<String, String> 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
Expand Down

0 comments on commit 9c31880

Please sign in to comment.