@@ -67,15 +67,15 @@ public final class Logger
6767 /**
6868 * The children of this logger. A logger may have zero or more children.
6969 */
70- transient private List <Logger > childrenList ;
70+ private final transient List <Logger > childrenList = new CopyOnWriteArrayList <>() ;
7171
7272 /**
7373 * It is assumed that once the 'aai' variable is set to a non-null value, it
7474 * will never be reset to null. it is further assumed that only place where the
7575 * 'aai variable is set is within the addAppender method. This method is
7676 * synchronized on 'this' (Logger) protecting against simultaneous
7777 * re-configuration of this logger (a very unlikely scenario).
78- *
78+ *
7979 * <p>
8080 * It is further assumed that the AppenderAttachableImpl is responsible for its
8181 * internal synchronization and thread safety. Thus, we can get away with *not*
@@ -130,9 +130,6 @@ private boolean isRootLogger() {
130130 }
131131
132132 Logger getChildByName (final String childName ) {
133- if (childrenList == null ) {
134- return null ;
135- }
136133 for (final Logger child : childrenList ) {
137134 if (childName .equals (child .getName ())) {
138135 return child ;
@@ -159,11 +156,9 @@ public synchronized void setLevel(Level newLevel) {
159156 effectiveLevelInt = newLevel .levelInt ;
160157 }
161158
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 );
167162 }
168163 // inform listeners
169164 loggerContext .fireOnLevelChange (this , newLevel );
@@ -182,10 +177,8 @@ private synchronized void handleParentLevelChange(int newParentLevelInt) {
182177 effectiveLevelInt = newParentLevelInt ;
183178
184179 // 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 );
189182 }
190183 }
191184 }
@@ -241,7 +234,7 @@ public Appender<ILoggingEvent> getAppender(String name) {
241234
242235 /**
243236 * Invoke all the appenders of this logger.
244- *
237+ *
245238 * @param event The event to log
246239 */
247240 public void callAppenders (ILoggingEvent event ) {
@@ -280,11 +273,11 @@ public boolean detachAppender(Appender<ILoggingEvent> appender) {
280273 * Create a child of this logger by suffix, that is, the part of the name
281274 * extending this logger. For example, if this logger is named "x.y" and the
282275 * lastPart is "z", then the created child logger will be named "x.y.z".
283- *
276+ *
284277 * <p>
285278 * IMPORTANT: Calls to this method must be within a synchronized block on this
286279 * logger.
287- *
280+ *
288281 * @param lastPart the suffix (i.e. last part) of the child logger name. This
289282 * parameter may not include dots, i.e. the logger separator
290283 * character.
@@ -297,9 +290,6 @@ Logger createChildByLastNamePart(final String lastPart) {
297290 "Child name [" + lastPart + " passed as parameter, may not include [" + CoreConstants .DOT + "]" );
298291 }
299292
300- if (childrenList == null ) {
301- childrenList = new CopyOnWriteArrayList <Logger >();
302- }
303293 Logger childLogger ;
304294 if (this .isRootLogger ()) {
305295 childLogger = new Logger (lastPart , this , this .loggerContext );
@@ -324,9 +314,6 @@ void recursiveReset() {
324314 detachAndStopAllAppenders ();
325315 localLevelReset ();
326316 additive = true ;
327- if (childrenList == null ) {
328- return ;
329- }
330317 for (Logger childLogger : childrenList ) {
331318 childLogger .recursiveReset ();
332319 }
@@ -339,9 +326,6 @@ synchronized Logger createChildByName(final String childName) {
339326 + " passed as parameter, may not include '.' after index" + (this .name .length () + 1 ));
340327 }
341328
342- if (childrenList == null ) {
343- childrenList = new CopyOnWriteArrayList <>();
344- }
345329 final Logger childLogger = new Logger (childName , this , this .loggerContext );
346330 childrenList .add (childLogger );
347331 childLogger .effectiveLevelInt = this .effectiveLevelInt ;
@@ -729,11 +713,11 @@ public String toString() {
729713 /**
730714 * Method that calls the attached TurboFilter objects based on the logger and
731715 * the level.
732- *
716+ *
733717 * It is used by isYYYEnabled() methods.
734- *
718+ *
735719 * It returns the typical FilterReply values: ACCEPT, NEUTRAL or DENY.
736- *
720+ *
737721 * @param level
738722 * @return the reply given by the TurboFilters
739723 */
@@ -743,7 +727,7 @@ private FilterReply callTurboFilters(Marker marker, Level level) {
743727
744728 /**
745729 * Return the context for this logger.
746- *
730+ *
747731 * @return the context
748732 */
749733 public LoggerContext getLoggerContext () {
@@ -752,7 +736,7 @@ public LoggerContext getLoggerContext() {
752736
753737 /**
754738 * Creates a {@link LoggingEventBuilder} of type {@link DefaultLoggingEventBuilder}.
755- *
739+ *
756740 * @since 1.3
757741 */
758742 @ Override
@@ -806,7 +790,7 @@ public void log(org.slf4j.event.LoggingEvent slf4jEvent) {
806790 * After serialization, the logger instance does not know its LoggerContext. The
807791 * best we can do here, is to return a logger with the same name returned by
808792 * org.slf4j.LoggerFactory.
809- *
793+ *
810794 * @return Logger instance with the same name
811795 * @throws ObjectStreamException
812796 */
0 commit comments