From 68f3b5d338c7d5ea6c8b79e3bc49e32e884cec02 Mon Sep 17 00:00:00 2001 From: Wenjun Ruan Date: Sun, 13 Oct 2024 21:01:03 +0800 Subject: [PATCH] Remove Unused comment in LoggerContext --- .../java/ch/qos/logback/classic/Logger.java | 65 +++++++------------ .../ch/qos/logback/classic/LoggerContext.java | 20 +++--- 2 files changed, 33 insertions(+), 52 deletions(-) diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java b/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java index 7793cc39cb..d7cfff5cf4 100644 --- a/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/Logger.java @@ -75,7 +75,7 @@ public final class Logger * 'aai variable is set is within the addAppender method. This method is * synchronized on 'this' (Logger) protecting against simultaneous * re-configuration of this logger (a very unlikely scenario). - * + * *

* It is further assumed that the AppenderAttachableImpl is responsible for its * internal synchronization and thread safety. Thus, we can get away with *not* @@ -132,19 +132,14 @@ private boolean isRootLogger() { Logger getChildByName(final String childName) { if (childrenList == null) { return null; - } else { - int len = this.childrenList.size(); - for (int i = 0; i < len; i++) { - final Logger childLogger_i = (Logger) childrenList.get(i); - final String childName_i = childLogger_i.getName(); - - if (childName.equals(childName_i)) { - return childLogger_i; - } + } + for (final Logger child : childrenList) { + if (childName.equals(child.getName())) { + return child; } - // no child found - return null; } + // no child found + return null; } public synchronized void setLevel(Level newLevel) { @@ -165,11 +160,9 @@ public synchronized void setLevel(Level newLevel) { } if (childrenList != null) { - int len = childrenList.size(); - for (int i = 0; i < len; i++) { - Logger child = (Logger) childrenList.get(i); + for (Logger childLogger : childrenList) { // tell child to handle parent levelInt change - child.handleParentLevelChange(effectiveLevelInt); + childLogger.handleParentLevelChange(effectiveLevelInt); } } // inform listeners @@ -179,7 +172,7 @@ public synchronized void setLevel(Level newLevel) { /** * This method is invoked by parent logger to let this logger know that the * prent's levelInt changed. - * + * * @param newParentLevelInt */ private synchronized void handleParentLevelChange(int newParentLevelInt) { @@ -190,10 +183,8 @@ private synchronized void handleParentLevelChange(int newParentLevelInt) { // propagate the parent levelInt change to this logger's children if (childrenList != null) { - int len = childrenList.size(); - for (int i = 0; i < len; i++) { - Logger child = (Logger) childrenList.get(i); - child.handleParentLevelChange(newParentLevelInt); + for (Logger childLogger : childrenList) { + childLogger.handleParentLevelChange(newParentLevelInt); } } } @@ -250,7 +241,7 @@ public Appender getAppender(String name) { /** * Invoke all the appenders of this logger. - * + * * @param event The event to log */ public void callAppenders(ILoggingEvent event) { @@ -289,11 +280,11 @@ public boolean detachAppender(Appender appender) { * Create a child of this logger by suffix, that is, the part of the name * extending this logger. For example, if this logger is named "x.y" and the * lastPart is "z", then the created child logger will be named "x.y.z". - * + * *

* IMPORTANT: Calls to this method must be within a synchronized block on this * logger. - * + * * @param lastPart the suffix (i.e. last part) of the child logger name. This * parameter may not include dots, i.e. the logger separator * character. @@ -341,12 +332,7 @@ void recursiveReset() { } } - /** - * The default size of child list arrays. The JDK 1.5 default is 10. We use a - * smaller value to save a little space. - */ - - Logger createChildByName(final String childName) { + synchronized Logger createChildByName(final String childName) { int i_index = LoggerNameUtil.getSeparatorIndexOf(childName, this.name.length() + 1); if (i_index != -1) { throw new IllegalArgumentException("For logger [" + this.name + "] child name [" + childName @@ -354,10 +340,9 @@ Logger createChildByName(final String childName) { } if (childrenList == null) { - childrenList = new CopyOnWriteArrayList(); + childrenList = new CopyOnWriteArrayList<>(); } - Logger childLogger; - childLogger = new Logger(childName, this, this.loggerContext); + final Logger childLogger = new Logger(childName, this, this.loggerContext); childrenList.add(childLogger); childLogger.effectiveLevelInt = this.effectiveLevelInt; return childLogger; @@ -744,11 +729,11 @@ public String toString() { /** * Method that calls the attached TurboFilter objects based on the logger and * the level. - * + * * It is used by isYYYEnabled() methods. - * + * * It returns the typical FilterReply values: ACCEPT, NEUTRAL or DENY. - * + * * @param level * @return the reply given by the TurboFilters */ @@ -758,7 +743,7 @@ private FilterReply callTurboFilters(Marker marker, Level level) { /** * Return the context for this logger. - * + * * @return the context */ public LoggerContext getLoggerContext() { @@ -767,7 +752,7 @@ public LoggerContext getLoggerContext() { /** * Creates a {@link LoggingEventBuilder} of type {@link DefaultLoggingEventBuilder}. - * + * * @since 1.3 */ @Override @@ -783,7 +768,7 @@ public void log(Marker marker, String fqcn, int levelInt, String message, Object /** * Support SLF4J interception during initialization as introduced in SLF4J * version 1.7.15 - * + * * @since 1.1.4 * @param slf4jEvent */ @@ -821,7 +806,7 @@ public void log(org.slf4j.event.LoggingEvent slf4jEvent) { * After serialization, the logger instance does not know its LoggerContext. The * best we can do here, is to return a logger with the same name returned by * org.slf4j.LoggerFactory. - * + * * @return Logger instance with the same name * @throws ObjectStreamException */ diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java b/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java index 8faed3ed3c..3056bdd81d 100755 --- a/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java +++ b/logback-classic/src/main/java/ch/qos/logback/classic/LoggerContext.java @@ -23,11 +23,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.locks.ReentrantLock; -import ch.qos.logback.classic.util.LogbackMDCAdapter; -import ch.qos.logback.core.status.ErrorStatus; -import ch.qos.logback.core.status.InfoStatus; import org.slf4j.ILoggerFactory; import org.slf4j.Marker; @@ -66,7 +62,7 @@ public class LoggerContext extends ContextBase implements ILoggerFactory, LifeCy final Logger root; private int size; private int noAppenderWarning = 0; - final private List loggerContextListenerList = new ArrayList(); + final private List loggerContextListenerList = new ArrayList<>(); private Map loggerCache; @@ -84,7 +80,7 @@ public class LoggerContext extends ContextBase implements ILoggerFactory, LifeCy public LoggerContext() { super(); - this.loggerCache = new ConcurrentHashMap(); + this.loggerCache = new ConcurrentHashMap<>(); this.loggerContextRemoteView = new LoggerContextVO(this); this.root = new Logger(Logger.ROOT_LOGGER_NAME, null, this); @@ -92,7 +88,7 @@ public LoggerContext() { loggerCache.put(Logger.ROOT_LOGGER_NAME, root); initEvaluatorMap(); size = 1; - this.frameworkPackages = new ArrayList(); + this.frameworkPackages = new ArrayList<>(); // In 1.5.7, the stop() method assumes that at some point the context has been started // since earlier versions of logback did not mandate calling the start method // we need to call in the constructor @@ -145,7 +141,7 @@ public Logger getLogger(final String name) { // check if the desired logger exists, if it does, return it // without further ado. - Logger childLogger = (Logger) loggerCache.get(name); + Logger childLogger = loggerCache.get(name); // if we have the child, then let us return it without wasting time if (childLogger != null) { return childLogger; @@ -193,7 +189,7 @@ int size() { * @param name the name of the logger to search for. */ public Logger exists(String name) { - return (Logger) loggerCache.get(name); + return loggerCache.get(name); } final void noAppenderDefinedWarning(final Logger logger) { @@ -204,7 +200,7 @@ final void noAppenderDefinedWarning(final Logger logger) { public List getLoggerList() { Collection collection = loggerCache.values(); - List loggerList = new ArrayList(collection); + List loggerList = new ArrayList<>(collection); Collections.sort(loggerList, new LoggerComparator()); return loggerList; } @@ -297,7 +293,7 @@ public void removeListener(LoggerContextListener listener) { } private void resetListenersExceptResetResistant() { - List toRetain = new ArrayList(); + List toRetain = new ArrayList<>(); for (LoggerContextListener lcl : loggerContextListenerList) { if (lcl.isResetResistant()) { @@ -312,7 +308,7 @@ private void resetAllListeners() { } public List getCopyOfListenerList() { - return new ArrayList(loggerContextListenerList); + return new ArrayList<>(loggerContextListenerList); } void fireOnLevelChange(Logger logger, Level level) {