1
1
package ch .qos .logback .classic .spi ;
2
2
3
+ import ch .qos .logback .classic .util .ContextSelectorStaticBinder ;
3
4
import org .slf4j .ILoggerFactory ;
4
5
import org .slf4j .IMarkerFactory ;
5
6
import org .slf4j .helpers .BasicMarkerFactory ;
@@ -28,11 +29,11 @@ public class LogbackServiceProvider implements SLF4JServiceProvider {
28
29
29
30
private LoggerContext defaultLoggerContext ;
30
31
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 ;
36
37
37
38
@ Override
38
39
public void initialize () {
@@ -57,7 +58,7 @@ private void initializeLoggerContext() {
57
58
if (!StatusUtil .contextHasStatusListener (defaultLoggerContext )) {
58
59
StatusPrinter .printInCaseOfErrorsOrWarnings (defaultLoggerContext );
59
60
}
60
- // contextSelectorBinder.init(defaultLoggerContext, KEY);
61
+ contextSelectorBinder .init (defaultLoggerContext , KEY );
61
62
62
63
} catch (Exception t ) { // see LOGBACK-1159
63
64
Util .report ("Failed to instantiate [" + LoggerContext .class .getName () + "]" , t );
@@ -67,16 +68,15 @@ private void initializeLoggerContext() {
67
68
@ Override
68
69
69
70
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 ();
80
80
}
81
81
82
82
@ Override
0 commit comments