@@ -75,7 +75,7 @@ public final class Logger
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*
@@ -132,19 +132,14 @@ private boolean isRootLogger() {
132
132
Logger getChildByName (final String childName ) {
133
133
if (childrenList == null ) {
134
134
return null ;
135
- } else {
136
- int len = this .childrenList .size ();
137
- for (int i = 0 ; i < len ; i ++) {
138
- final Logger childLogger_i = (Logger ) childrenList .get (i );
139
- final String childName_i = childLogger_i .getName ();
140
-
141
- if (childName .equals (childName_i )) {
142
- return childLogger_i ;
143
- }
135
+ }
136
+ for (final Logger child : childrenList ) {
137
+ if (childName .equals (child .getName ())) {
138
+ return child ;
144
139
}
145
- // no child found
146
- return null ;
147
140
}
141
+ // no child found
142
+ return null ;
148
143
}
149
144
150
145
public synchronized void setLevel (Level newLevel ) {
@@ -165,11 +160,9 @@ public synchronized void setLevel(Level newLevel) {
165
160
}
166
161
167
162
if (childrenList != null ) {
168
- int len = childrenList .size ();
169
- for (int i = 0 ; i < len ; i ++) {
170
- Logger child = (Logger ) childrenList .get (i );
163
+ for (Logger childLogger : childrenList ) {
171
164
// tell child to handle parent levelInt change
172
- child .handleParentLevelChange (effectiveLevelInt );
165
+ childLogger .handleParentLevelChange (effectiveLevelInt );
173
166
}
174
167
}
175
168
// inform listeners
@@ -179,7 +172,7 @@ public synchronized void setLevel(Level newLevel) {
179
172
/**
180
173
* This method is invoked by parent logger to let this logger know that the
181
174
* prent's levelInt changed.
182
- *
175
+ *
183
176
* @param newParentLevelInt
184
177
*/
185
178
private synchronized void handleParentLevelChange (int newParentLevelInt ) {
@@ -190,10 +183,8 @@ private synchronized void handleParentLevelChange(int newParentLevelInt) {
190
183
191
184
// propagate the parent levelInt change to this logger's children
192
185
if (childrenList != null ) {
193
- int len = childrenList .size ();
194
- for (int i = 0 ; i < len ; i ++) {
195
- Logger child = (Logger ) childrenList .get (i );
196
- child .handleParentLevelChange (newParentLevelInt );
186
+ for (Logger childLogger : childrenList ) {
187
+ childLogger .handleParentLevelChange (newParentLevelInt );
197
188
}
198
189
}
199
190
}
@@ -250,7 +241,7 @@ public Appender<ILoggingEvent> getAppender(String name) {
250
241
251
242
/**
252
243
* Invoke all the appenders of this logger.
253
- *
244
+ *
254
245
* @param event The event to log
255
246
*/
256
247
public void callAppenders (ILoggingEvent event ) {
@@ -289,11 +280,11 @@ public boolean detachAppender(Appender<ILoggingEvent> appender) {
289
280
* Create a child of this logger by suffix, that is, the part of the name
290
281
* extending this logger. For example, if this logger is named "x.y" and the
291
282
* lastPart is "z", then the created child logger will be named "x.y.z".
292
- *
283
+ *
293
284
* <p>
294
285
* IMPORTANT: Calls to this method must be within a synchronized block on this
295
286
* logger.
296
- *
287
+ *
297
288
* @param lastPart the suffix (i.e. last part) of the child logger name. This
298
289
* parameter may not include dots, i.e. the logger separator
299
290
* character.
@@ -341,23 +332,17 @@ void recursiveReset() {
341
332
}
342
333
}
343
334
344
- /**
345
- * The default size of child list arrays. The JDK 1.5 default is 10. We use a
346
- * smaller value to save a little space.
347
- */
348
-
349
- Logger createChildByName (final String childName ) {
335
+ synchronized Logger createChildByName (final String childName ) {
350
336
int i_index = LoggerNameUtil .getSeparatorIndexOf (childName , this .name .length () + 1 );
351
337
if (i_index != -1 ) {
352
338
throw new IllegalArgumentException ("For logger [" + this .name + "] child name [" + childName
353
339
+ " passed as parameter, may not include '.' after index" + (this .name .length () + 1 ));
354
340
}
355
341
356
342
if (childrenList == null ) {
357
- childrenList = new CopyOnWriteArrayList <Logger >();
343
+ childrenList = new CopyOnWriteArrayList <>();
358
344
}
359
- Logger childLogger ;
360
- childLogger = new Logger (childName , this , this .loggerContext );
345
+ final Logger childLogger = new Logger (childName , this , this .loggerContext );
361
346
childrenList .add (childLogger );
362
347
childLogger .effectiveLevelInt = this .effectiveLevelInt ;
363
348
return childLogger ;
@@ -744,11 +729,11 @@ public String toString() {
744
729
/**
745
730
* Method that calls the attached TurboFilter objects based on the logger and
746
731
* the level.
747
- *
732
+ *
748
733
* It is used by isYYYEnabled() methods.
749
- *
734
+ *
750
735
* It returns the typical FilterReply values: ACCEPT, NEUTRAL or DENY.
751
- *
736
+ *
752
737
* @param level
753
738
* @return the reply given by the TurboFilters
754
739
*/
@@ -758,7 +743,7 @@ private FilterReply callTurboFilters(Marker marker, Level level) {
758
743
759
744
/**
760
745
* Return the context for this logger.
761
- *
746
+ *
762
747
* @return the context
763
748
*/
764
749
public LoggerContext getLoggerContext () {
@@ -767,7 +752,7 @@ public LoggerContext getLoggerContext() {
767
752
768
753
/**
769
754
* Creates a {@link LoggingEventBuilder} of type {@link DefaultLoggingEventBuilder}.
770
- *
755
+ *
771
756
* @since 1.3
772
757
*/
773
758
@ Override
@@ -783,7 +768,7 @@ public void log(Marker marker, String fqcn, int levelInt, String message, Object
783
768
/**
784
769
* Support SLF4J interception during initialization as introduced in SLF4J
785
770
* version 1.7.15
786
- *
771
+ *
787
772
* @since 1.1.4
788
773
* @param slf4jEvent
789
774
*/
@@ -821,7 +806,7 @@ public void log(org.slf4j.event.LoggingEvent slf4jEvent) {
821
806
* After serialization, the logger instance does not know its LoggerContext. The
822
807
* best we can do here, is to return a logger with the same name returned by
823
808
* org.slf4j.LoggerFactory.
824
- *
809
+ *
825
810
* @return Logger instance with the same name
826
811
* @throws ObjectStreamException
827
812
*/
0 commit comments