Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recover contextSelector #766

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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