11package ch .qos .logback .classic .spi ;
22
3+ import ch .qos .logback .classic .util .ContextSelectorStaticBinder ;
34import org .slf4j .ILoggerFactory ;
45import org .slf4j .IMarkerFactory ;
56import org .slf4j .helpers .BasicMarkerFactory ;
@@ -28,11 +29,11 @@ public class LogbackServiceProvider implements SLF4JServiceProvider {
2829
2930 private LoggerContext defaultLoggerContext ;
3031 private IMarkerFactory markerFactory ;
31- private LogbackMDCAdapter mdcAdapter ;
32- // private final ContextSelectorStaticBinder contextSelectorBinder =
33- // ContextSelectorStaticBinder.getSingleton();
34- // private static Object KEY = new Object();
35- // private volatile boolean initialized = false;
32+ private LogbackMDCAdapter mdcAdapter ;
33+ private final ContextSelectorStaticBinder contextSelectorBinder =
34+ ContextSelectorStaticBinder .getSingleton ();
35+ private static Object KEY = new Object ();
36+ private volatile boolean initialized = false ;
3637
3738 @ Override
3839 public void initialize () {
@@ -57,7 +58,7 @@ private void initializeLoggerContext() {
5758 if (!StatusUtil .contextHasStatusListener (defaultLoggerContext )) {
5859 StatusPrinter .printInCaseOfErrorsOrWarnings (defaultLoggerContext );
5960 }
60- // contextSelectorBinder.init(defaultLoggerContext, KEY);
61+ contextSelectorBinder .init (defaultLoggerContext , KEY );
6162
6263 } catch (Exception t ) { // see LOGBACK-1159
6364 Util .report ("Failed to instantiate [" + LoggerContext .class .getName () + "]" , t );
@@ -67,16 +68,15 @@ private void initializeLoggerContext() {
6768 @ Override
6869
6970 public ILoggerFactory getLoggerFactory () {
70- return defaultLoggerContext ;
71-
72- // if (!initialized) {
73- // return defaultLoggerContext;
74- //
75- //
76- // if (contextSelectorBinder.getContextSelector() == null) {
77- // throw new IllegalStateException("contextSelector cannot be null. See also " + NULL_CS_URL);
78- // }
79- // return contextSelectorBinder.getContextSelector().getLoggerContext();
71+ if (!initialized ) {
72+ return defaultLoggerContext ;
73+ }
74+
75+
76+ if (contextSelectorBinder .getContextSelector () == null ) {
77+ throw new IllegalStateException ("contextSelector cannot be null. See also " + NULL_CS_URL );
78+ }
79+ return contextSelectorBinder .getContextSelector ().getLoggerContext ();
8080 }
8181
8282 @ Override
0 commit comments