@@ -67,15 +67,15 @@ public final class Logger
67
67
/**
68
68
* The children of this logger. A logger may have zero or more children.
69
69
*/
70
- transient private List <Logger > childrenList ;
70
+ private final transient List <Logger > childrenList = new CopyOnWriteArrayList <>() ;
71
71
72
72
/**
73
73
* It is assumed that once the 'aai' variable is set to a non-null value, it
74
74
* will never be reset to null. it is further assumed that only place where the
75
75
* 'aai variable is set is within the addAppender method. This method is
76
76
* synchronized on 'this' (Logger) protecting against simultaneous
77
77
* re-configuration of this logger (a very unlikely scenario).
78
- *
78
+ *
79
79
* <p>
80
80
* It is further assumed that the AppenderAttachableImpl is responsible for its
81
81
* internal synchronization and thread safety. Thus, we can get away with *not*
@@ -130,9 +130,6 @@ private boolean isRootLogger() {
130
130
}
131
131
132
132
Logger getChildByName (final String childName ) {
133
- if (childrenList == null ) {
134
- return null ;
135
- }
136
133
for (final Logger child : childrenList ) {
137
134
if (childName .equals (child .getName ())) {
138
135
return child ;
@@ -159,11 +156,9 @@ public synchronized void setLevel(Level newLevel) {
159
156
effectiveLevelInt = newLevel .levelInt ;
160
157
}
161
158
162
- if (childrenList != null ) {
163
- for (Logger childLogger : childrenList ) {
164
- // tell child to handle parent levelInt change
165
- childLogger .handleParentLevelChange (effectiveLevelInt );
166
- }
159
+ for (Logger childLogger : childrenList ) {
160
+ // tell child to handle parent levelInt change
161
+ childLogger .handleParentLevelChange (effectiveLevelInt );
167
162
}
168
163
// inform listeners
169
164
loggerContext .fireOnLevelChange (this , newLevel );
@@ -172,7 +167,7 @@ public synchronized void setLevel(Level newLevel) {
172
167
/**
173
168
* This method is invoked by parent logger to let this logger know that the
174
169
* prent's levelInt changed.
175
- *
170
+ *
176
171
* @param newParentLevelInt
177
172
*/
178
173
private synchronized void handleParentLevelChange (int newParentLevelInt ) {
@@ -182,10 +177,8 @@ private synchronized void handleParentLevelChange(int newParentLevelInt) {
182
177
effectiveLevelInt = newParentLevelInt ;
183
178
184
179
// propagate the parent levelInt change to this logger's children
185
- if (childrenList != null ) {
186
- for (Logger childLogger : childrenList ) {
187
- childLogger .handleParentLevelChange (newParentLevelInt );
188
- }
180
+ for (Logger childLogger : childrenList ) {
181
+ childLogger .handleParentLevelChange (newParentLevelInt );
189
182
}
190
183
}
191
184
}
@@ -241,7 +234,7 @@ public Appender<ILoggingEvent> getAppender(String name) {
241
234
242
235
/**
243
236
* Invoke all the appenders of this logger.
244
- *
237
+ *
245
238
* @param event The event to log
246
239
*/
247
240
public void callAppenders (ILoggingEvent event ) {
@@ -280,11 +273,11 @@ public boolean detachAppender(Appender<ILoggingEvent> appender) {
280
273
* Create a child of this logger by suffix, that is, the part of the name
281
274
* extending this logger. For example, if this logger is named "x.y" and the
282
275
* lastPart is "z", then the created child logger will be named "x.y.z".
283
- *
276
+ *
284
277
* <p>
285
278
* IMPORTANT: Calls to this method must be within a synchronized block on this
286
279
* logger.
287
- *
280
+ *
288
281
* @param lastPart the suffix (i.e. last part) of the child logger name. This
289
282
* parameter may not include dots, i.e. the logger separator
290
283
* character.
@@ -297,9 +290,6 @@ Logger createChildByLastNamePart(final String lastPart) {
297
290
"Child name [" + lastPart + " passed as parameter, may not include [" + CoreConstants .DOT + "]" );
298
291
}
299
292
300
- if (childrenList == null ) {
301
- childrenList = new CopyOnWriteArrayList <Logger >();
302
- }
303
293
Logger childLogger ;
304
294
if (this .isRootLogger ()) {
305
295
childLogger = new Logger (lastPart , this , this .loggerContext );
@@ -324,9 +314,6 @@ void recursiveReset() {
324
314
detachAndStopAllAppenders ();
325
315
localLevelReset ();
326
316
additive = true ;
327
- if (childrenList == null ) {
328
- return ;
329
- }
330
317
for (Logger childLogger : childrenList ) {
331
318
childLogger .recursiveReset ();
332
319
}
@@ -339,9 +326,6 @@ synchronized Logger createChildByName(final String childName) {
339
326
+ " passed as parameter, may not include '.' after index" + (this .name .length () + 1 ));
340
327
}
341
328
342
- if (childrenList == null ) {
343
- childrenList = new CopyOnWriteArrayList <>();
344
- }
345
329
final Logger childLogger = new Logger (childName , this , this .loggerContext );
346
330
childrenList .add (childLogger );
347
331
childLogger .effectiveLevelInt = this .effectiveLevelInt ;
@@ -729,11 +713,11 @@ public String toString() {
729
713
/**
730
714
* Method that calls the attached TurboFilter objects based on the logger and
731
715
* the level.
732
- *
716
+ *
733
717
* It is used by isYYYEnabled() methods.
734
- *
718
+ *
735
719
* It returns the typical FilterReply values: ACCEPT, NEUTRAL or DENY.
736
- *
720
+ *
737
721
* @param level
738
722
* @return the reply given by the TurboFilters
739
723
*/
@@ -743,7 +727,7 @@ private FilterReply callTurboFilters(Marker marker, Level level) {
743
727
744
728
/**
745
729
* Return the context for this logger.
746
- *
730
+ *
747
731
* @return the context
748
732
*/
749
733
public LoggerContext getLoggerContext () {
@@ -752,7 +736,7 @@ public LoggerContext getLoggerContext() {
752
736
753
737
/**
754
738
* Creates a {@link LoggingEventBuilder} of type {@link DefaultLoggingEventBuilder}.
755
- *
739
+ *
756
740
* @since 1.3
757
741
*/
758
742
@ Override
@@ -806,7 +790,7 @@ public void log(org.slf4j.event.LoggingEvent slf4jEvent) {
806
790
* After serialization, the logger instance does not know its LoggerContext. The
807
791
* best we can do here, is to return a logger with the same name returned by
808
792
* org.slf4j.LoggerFactory.
809
- *
793
+ *
810
794
* @return Logger instance with the same name
811
795
* @throws ObjectStreamException
812
796
*/
0 commit comments