Skip to content

Commit

Permalink
Remove Unused comment in LoggerContext
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanwenjun committed Oct 13, 2024
1 parent 8749edc commit 68f3b5d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 52 deletions.
65 changes: 25 additions & 40 deletions logback-classic/src/main/java/ch/qos/logback/classic/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*
*
* <p>
* It is further assumed that the AppenderAttachableImpl is responsible for its
* internal synchronization and thread safety. Thus, we can get away with *not*
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -250,7 +241,7 @@ public Appender<ILoggingEvent> getAppender(String name) {

/**
* Invoke all the appenders of this logger.
*
*
* @param event The event to log
*/
public void callAppenders(ILoggingEvent event) {
Expand Down Expand Up @@ -289,11 +280,11 @@ public boolean detachAppender(Appender<ILoggingEvent> 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".
*
*
* <p>
* 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.
Expand Down Expand Up @@ -341,23 +332,17 @@ 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
+ " passed as parameter, may not include '.' after index" + (this.name.length() + 1));
}

if (childrenList == null) {
childrenList = new CopyOnWriteArrayList<Logger>();
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;
Expand Down Expand Up @@ -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
*/
Expand All @@ -758,7 +743,7 @@ private FilterReply callTurboFilters(Marker marker, Level level) {

/**
* Return the context for this logger.
*
*
* @return the context
*/
public LoggerContext getLoggerContext() {
Expand All @@ -767,7 +752,7 @@ public LoggerContext getLoggerContext() {

/**
* Creates a {@link LoggingEventBuilder} of type {@link DefaultLoggingEventBuilder}.
*
*
* @since 1.3
*/
@Override
Expand All @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<LoggerContextListener> loggerContextListenerList = new ArrayList<LoggerContextListener>();
final private List<LoggerContextListener> loggerContextListenerList = new ArrayList<>();

private Map<String, Logger> loggerCache;

Expand All @@ -84,15 +80,15 @@ public class LoggerContext extends ContextBase implements ILoggerFactory, LifeCy

public LoggerContext() {
super();
this.loggerCache = new ConcurrentHashMap<String, Logger>();
this.loggerCache = new ConcurrentHashMap<>();

this.loggerContextRemoteView = new LoggerContextVO(this);
this.root = new Logger(Logger.ROOT_LOGGER_NAME, null, this);
this.root.setLevel(Level.DEBUG);
loggerCache.put(Logger.ROOT_LOGGER_NAME, root);
initEvaluatorMap();
size = 1;
this.frameworkPackages = new ArrayList<String>();
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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -204,7 +200,7 @@ final void noAppenderDefinedWarning(final Logger logger) {

public List<Logger> getLoggerList() {
Collection<Logger> collection = loggerCache.values();
List<Logger> loggerList = new ArrayList<Logger>(collection);
List<Logger> loggerList = new ArrayList<>(collection);
Collections.sort(loggerList, new LoggerComparator());
return loggerList;
}
Expand Down Expand Up @@ -297,7 +293,7 @@ public void removeListener(LoggerContextListener listener) {
}

private void resetListenersExceptResetResistant() {
List<LoggerContextListener> toRetain = new ArrayList<LoggerContextListener>();
List<LoggerContextListener> toRetain = new ArrayList<>();

for (LoggerContextListener lcl : loggerContextListenerList) {
if (lcl.isResetResistant()) {
Expand All @@ -312,7 +308,7 @@ private void resetAllListeners() {
}

public List<LoggerContextListener> getCopyOfListenerList() {
return new ArrayList<LoggerContextListener>(loggerContextListenerList);
return new ArrayList<>(loggerContextListenerList);
}

void fireOnLevelChange(Logger logger, Level level) {
Expand Down

0 comments on commit 68f3b5d

Please sign in to comment.