Commit 40b3e51 1 parent 9bd0374 commit 40b3e51 Copy full SHA for 40b3e51
File tree 6 files changed +55
-14
lines changed
slf4j-api/src/main/java/org/slf4j
slf4j-jdk14/src/main/java/org/slf4j/jul
slf4j-nop/src/main/java/org/slf4j/nop
slf4j-reload4j/src/main/java/org/slf4j/reload4j
slf4j-simple/src/main/java/org/slf4j/simple
6 files changed +55
-14
lines changed Original file line number Diff line number Diff line change @@ -220,8 +220,8 @@ private final static void bind() {
220
220
/**
221
221
* The value of PROVIDER.getMDCAdapter() can be null while PROVIDER has not yet initialized.
222
222
*
223
- * However,
224
- *
223
+ * However, SLF4JServiceProvider implementations are expected to initialize their internal
224
+ * MDCAdapter field in their constructor or on field declaration.
225
225
*/
226
226
private static void earlyBindMDCAdapter () {
227
227
MDCAdapter mdcAdapter = PROVIDER .getMDCAdapter ();
Original file line number Diff line number Diff line change 7
7
8
8
public class SubstituteServiceProvider implements SLF4JServiceProvider {
9
9
private final SubstituteLoggerFactory loggerFactory = new SubstituteLoggerFactory ();
10
- private final IMarkerFactory markerFactory = new BasicMarkerFactory ();
11
- private final MDCAdapter mdcAdapter = new BasicMDCAdapter ();
10
+
11
+ // LoggerFactory expects providers to initialize markerFactory as early as possible.
12
+ private final IMarkerFactory markerFactory ;
13
+
14
+ // LoggerFactory expects providers to initialize their MDCAdapter field
15
+ // as early as possible, preferably at construction time.
16
+ private final MDCAdapter mdcAdapter ;
17
+
18
+ public SubstituteServiceProvider () {
19
+ markerFactory = new BasicMarkerFactory ();
20
+ mdcAdapter = new BasicMDCAdapter ();
21
+ }
12
22
13
23
@ Override
14
24
public ILoggerFactory getLoggerFactory () {
@@ -36,6 +46,5 @@ public String getRequestedApiVersion() {
36
46
37
47
@ Override
38
48
public void initialize () {
39
-
40
49
}
41
50
}
Original file line number Diff line number Diff line change @@ -17,8 +17,16 @@ public class JULServiceProvider implements SLF4JServiceProvider {
17
17
public static String REQUESTED_API_VERSION = "2.0.99" ; // !final
18
18
19
19
private ILoggerFactory loggerFactory ;
20
- private IMarkerFactory markerFactory = new BasicMarkerFactory ();
21
- private MDCAdapter mdcAdapter = new BasicMDCAdapter ();
20
+ // LoggerFactory expects providers to initialize markerFactory as early as possible.
21
+ private final IMarkerFactory markerFactory ;
22
+ // LoggerFactory expects providers to initialize their MDCAdapter field
23
+ // as early as possible, preferably at construction time.
24
+ private final MDCAdapter mdcAdapter ;
25
+
26
+ public JULServiceProvider () {
27
+ markerFactory = new BasicMarkerFactory ();
28
+ mdcAdapter = new BasicMDCAdapter ();
29
+ }
22
30
23
31
@ Override
24
32
public ILoggerFactory getLoggerFactory () {
Original file line number Diff line number Diff line change @@ -23,9 +23,18 @@ public class NOPServiceProvider implements SLF4JServiceProvider {
23
23
public static String REQUESTED_API_VERSION = "2.0.99" ; // !final
24
24
25
25
private final ILoggerFactory loggerFactory = new NOPLoggerFactory ();
26
- private final IMarkerFactory markerFactory = new BasicMarkerFactory ();
27
- private final MDCAdapter mdcAdapter = new NOPMDCAdapter ();
28
26
27
+ // LoggerFactory expects providers to initialize markerFactory as early as possible.
28
+ private final IMarkerFactory markerFactory ;
29
+
30
+ // LoggerFactory expects providers to initialize their MDCAdapter field
31
+ // as early as possible, preferably at construction time.
32
+ private final MDCAdapter mdcAdapter ;
33
+
34
+ public NOPServiceProvider () {
35
+ markerFactory = new BasicMarkerFactory ();
36
+ mdcAdapter = new NOPMDCAdapter ();
37
+ }
29
38
public ILoggerFactory getLoggerFactory () {
30
39
return loggerFactory ;
31
40
}
@@ -44,7 +53,6 @@ public String getRequestedApiVersion() {
44
53
}
45
54
46
55
public void initialize () {
47
-
48
56
}
49
57
50
58
Original file line number Diff line number Diff line change @@ -19,10 +19,17 @@ public class Reload4jServiceProvider implements SLF4JServiceProvider {
19
19
public static String REQUESTED_API_VERSION = "2.0.99" ; // !final
20
20
21
21
private ILoggerFactory loggerFactory ;
22
- private IMarkerFactory markerFactory = new BasicMarkerFactory ();
23
- private MDCAdapter mdcAdapter = new Reload4jMDCAdapter ();
22
+
23
+ // LoggerFactory expects providers to initialize markerFactory as early as possible.
24
+ private final IMarkerFactory markerFactory ;
25
+
26
+ // LoggerFactory expects providers to have a valid MDCAdapter field
27
+ // as early as possible, preferably at construction time.
28
+ private final MDCAdapter mdcAdapter ;
24
29
25
30
public Reload4jServiceProvider () {
31
+ markerFactory = new BasicMarkerFactory ();
32
+ mdcAdapter = new Reload4jMDCAdapter ();
26
33
try {
27
34
@ SuppressWarnings ("unused" )
28
35
Level level = Level .TRACE ;
Original file line number Diff line number Diff line change @@ -17,8 +17,16 @@ public class SimpleServiceProvider implements SLF4JServiceProvider {
17
17
public static String REQUESTED_API_VERSION = "2.0.99" ; // !final
18
18
19
19
private ILoggerFactory loggerFactory ;
20
- private IMarkerFactory = new BasicMarkerFactory ();
21
- private MDCAdapter mdcAdapter = new NOPMDCAdapter ();
20
+ // LoggerFactory expects providers to initialize markerFactory as early as possible.
21
+ private final IMarkerFactory markerFactory ;
22
+ // LoggerFactory expects providers to initialize their MDCAdapter field
23
+ // as early as possible, preferably at construction time.
24
+ private final MDCAdapter mdcAdapter ;
25
+
26
+ public SimpleServiceProvider () {
27
+ markerFactory = new BasicMarkerFactory ();
28
+ mdcAdapter = new NOPMDCAdapter ();
29
+ }
22
30
23
31
public ILoggerFactory getLoggerFactory () {
24
32
return loggerFactory ;
@@ -42,6 +50,7 @@ public String getRequestedApiVersion() {
42
50
@ Override
43
51
public void initialize () {
44
52
loggerFactory = new SimpleLoggerFactory ();
53
+
45
54
}
46
55
47
56
}
You can’t perform that action at this time.
0 commit comments