28
28
import org .apache .logging .log4j .core .config .LoggerConfig ;
29
29
import org .apache .logging .log4j .core .config .ReliabilityStrategy ;
30
30
import org .apache .logging .log4j .core .filter .CompositeFilter ;
31
+ import org .apache .logging .log4j .message .FlowMessageFactory ;
31
32
import org .apache .logging .log4j .message .Message ;
32
33
import org .apache .logging .log4j .message .MessageFactory ;
33
- import org .apache .logging .log4j .message . SimpleMessage ;
34
- import org .apache .logging .log4j .spi .AbstractLogger ;
34
+ import org .apache .logging .log4j .sdk . logger . AbstractLogger ;
35
+ import org .apache .logging .log4j .spi .recycler . RecyclerFactory ;
35
36
import org .apache .logging .log4j .util .Strings ;
36
37
import org .apache .logging .log4j .util .Supplier ;
38
+ import org .jspecify .annotations .NullMarked ;
39
+ import org .jspecify .annotations .Nullable ;
37
40
38
41
/**
39
42
* The core implementation of the {@link org.apache.logging.log4j.Logger} interface. Besides providing an implementation
43
46
* unit tests or bridging legacy Log4j 1.x code. Future versions of this class may or may not include the various
44
47
* methods that are noted as not being part of the public API.
45
48
*/
49
+ @ NullMarked
46
50
public class Logger extends AbstractLogger implements Supplier <LoggerConfig > {
47
51
48
52
/**
49
53
* Config should be consistent across threads.
50
54
*/
51
55
protected volatile PrivateConfig privateConfig ;
52
56
53
- // FIXME: ditto to the above
54
57
private final LoggerContext context ;
55
58
56
59
/**
57
60
* The constructor.
58
61
*
59
62
* @param context The LoggerContext this Logger is associated with.
60
- * @param messageFactory The message factory.
61
63
* @param name The name of the Logger.
64
+ * @param messageFactory The message factory to use for logging methods.
65
+ * @param flowMessageFactory The flow message factory to use for flow logging methods.
66
+ * @param recyclerFactory The recycler to use for log builder instances.
62
67
*/
63
- protected Logger (final LoggerContext context , final String name , final MessageFactory messageFactory ) {
64
- super (name , messageFactory );
68
+ protected Logger (
69
+ final LoggerContext context ,
70
+ final String name ,
71
+ final MessageFactory messageFactory ,
72
+ final FlowMessageFactory flowMessageFactory ,
73
+ final RecyclerFactory recyclerFactory ,
74
+ final org .apache .logging .log4j .Logger statusLogger ) {
75
+ super (name , messageFactory , flowMessageFactory , recyclerFactory , statusLogger );
65
76
this .context = context ;
66
77
privateConfig = new PrivateConfig (context .getConfiguration (), this );
67
78
}
68
79
69
- /**
70
- * This is used to construct an InternalLoggerContext, which makes SimpleLoggerContext conmpatible with core.
71
- * @param context the InternalLoggerContext.
72
- * @param name the Logger name.
73
- */
74
- protected Logger (final LoggerContext context , final String name ) {
75
- super (name );
76
- this .context = context ;
77
- privateConfig = null ;
78
- }
79
-
80
80
/**
81
81
* This method is only used for 1.x compatibility. Returns the parent of this Logger. If it doesn't already exist
82
82
* return a temporary Logger.
@@ -95,10 +95,7 @@ private Logger getParent(final PrivateConfig config) {
95
95
}
96
96
final String lcName = lc .getName ();
97
97
final MessageFactory messageFactory = getMessageFactory ();
98
- if (context .hasLogger (lcName , messageFactory )) {
99
- return context .getLogger (lcName , messageFactory );
100
- }
101
- return new Logger (context , lcName , messageFactory );
98
+ return context .getLogger (lcName , messageFactory );
102
99
}
103
100
104
101
/**
@@ -149,35 +146,32 @@ protected boolean requiresLocation() {
149
146
}
150
147
151
148
@ Override
152
- public void logMessage (
153
- final String fqcn , final Level level , final Marker marker , final Message message , final Throwable t ) {
154
- final Message msg = message == null ? new SimpleMessage (Strings .EMPTY ) : message ;
155
- final ReliabilityStrategy strategy = privateConfig .loggerConfig .getReliabilityStrategy ();
156
- strategy .log (this , getName (), fqcn , marker , level , msg , t );
157
- }
158
-
159
- @ Override
160
- protected void log (
161
- final Level level ,
162
- final Marker marker ,
149
+ protected void doLog (
163
150
final String fqcn ,
164
- final StackTraceElement location ,
165
- final Message message ,
166
- final Throwable throwable ) {
151
+ final @ Nullable StackTraceElement location ,
152
+ final Level level ,
153
+ final @ Nullable Marker marker ,
154
+ final @ Nullable Message message ,
155
+ final @ Nullable Throwable throwable ) {
167
156
final ReliabilityStrategy strategy = privateConfig .loggerConfig .getReliabilityStrategy ();
168
157
strategy .log (this , getName (), fqcn , location , marker , level , message , throwable );
169
158
}
170
159
171
160
@ Override
172
- public boolean isEnabled (final Level level , final Marker marker , final String message , final Throwable t ) {
173
- return privateConfig .filter (level , marker , message , t );
161
+ public boolean isEnabled (final Level level , final Marker marker ) {
162
+ return privateConfig .filter (level , marker , null );
174
163
}
175
164
176
165
@ Override
177
166
public boolean isEnabled (final Level level , final Marker marker , final String message ) {
178
167
return privateConfig .filter (level , marker , message );
179
168
}
180
169
170
+ @ Override
171
+ public boolean isEnabled (final Level level , final Marker marker , final String message , final Throwable t ) {
172
+ return privateConfig .filter (level , marker , message , t );
173
+ }
174
+
181
175
@ Override
182
176
public boolean isEnabled (final Level level , final Marker marker , final String message , final Object ... params ) {
183
177
return privateConfig .filter (level , marker , message , params );
0 commit comments