Skip to content

Commit

Permalink
recover contextSelector
Browse files Browse the repository at this point in the history
Signed-off-by: lvjing2 <leojames.googol@gmail.com>
  • Loading branch information
lvjing2 committed Jan 11, 2024
1 parent f3efb8f commit 30b1721
Showing 1 changed file with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ch.qos.logback.classic.spi;

import ch.qos.logback.classic.util.ContextSelectorStaticBinder;
import org.slf4j.ILoggerFactory;
import org.slf4j.IMarkerFactory;
import org.slf4j.helpers.BasicMarkerFactory;
Expand Down Expand Up @@ -28,11 +29,11 @@ public class LogbackServiceProvider implements SLF4JServiceProvider {

private LoggerContext defaultLoggerContext;
private IMarkerFactory markerFactory;
private LogbackMDCAdapter mdcAdapter;
// private final ContextSelectorStaticBinder contextSelectorBinder =
// ContextSelectorStaticBinder.getSingleton();
// private static Object KEY = new Object();
// private volatile boolean initialized = false;
private LogbackMDCAdapter mdcAdapter;
private final ContextSelectorStaticBinder contextSelectorBinder =
ContextSelectorStaticBinder.getSingleton();
private static Object KEY = new Object();
private volatile boolean initialized = false;

@Override
public void initialize() {
Expand All @@ -57,7 +58,7 @@ private void initializeLoggerContext() {
if (!StatusUtil.contextHasStatusListener(defaultLoggerContext)) {
StatusPrinter.printInCaseOfErrorsOrWarnings(defaultLoggerContext);
}
// contextSelectorBinder.init(defaultLoggerContext, KEY);
contextSelectorBinder.init(defaultLoggerContext, KEY);

} catch (Exception t) { // see LOGBACK-1159
Util.report("Failed to instantiate [" + LoggerContext.class.getName() + "]", t);
Expand All @@ -67,16 +68,15 @@ private void initializeLoggerContext() {
@Override

public ILoggerFactory getLoggerFactory() {
return defaultLoggerContext;

// if (!initialized) {
// return defaultLoggerContext;
//
//
// if (contextSelectorBinder.getContextSelector() == null) {
// throw new IllegalStateException("contextSelector cannot be null. See also " + NULL_CS_URL);
// }
// return contextSelectorBinder.getContextSelector().getLoggerContext();
if (!initialized) {
return defaultLoggerContext;
}


if (contextSelectorBinder.getContextSelector() == null) {
throw new IllegalStateException("contextSelector cannot be null. See also " + NULL_CS_URL);
}
return contextSelectorBinder.getContextSelector().getLoggerContext();
}

@Override
Expand Down

0 comments on commit 30b1721

Please sign in to comment.