vy commented on code in PR #3474: URL: https://github.com/apache/logging-log4j2/pull/3474#discussion_r1965497205
########## log4j-core/src/main/java/org/apache/logging/log4j/core/util/internal/InternalLoggerRegistry.java: ########## @@ -39,10 +41,8 @@ /** * A registry of {@link Logger}s namespaced by name and message factory. * This class is internally used by {@link LoggerContext}. - * <p> - * We don't use {@linkplain org.apache.logging.log4j.spi.LoggerRegistry the registry from Log4j API} to keep Log4j Core independent from the version of Log4j API at runtime. - * This also allows Log4j Core to evolve independently from Log4j API. - * </p> Review Comment: Why do you remove these? ########## log4j-core/src/main/java/org/apache/logging/log4j/core/util/internal/InternalLoggerRegistry.java: ########## @@ -53,23 +53,44 @@ public final class InternalLoggerRegistry { new WeakHashMap<>(); private final ReadWriteLock lock = new ReentrantReadWriteLock(); - private final Lock readLock = lock.readLock(); - private final Lock writeLock = lock.writeLock(); + // ReferenceQueue to track stale WeakReferences + private final ReferenceQueue<Logger> staleLoggerRefs = new ReferenceQueue<>(); + public InternalLoggerRegistry() {} + /** + * Expunges stale logger references from the registry. + */ + private void expungeStaleEntries() { + Reference<? extends Logger> loggerRef; + while ((loggerRef = staleLoggerRefs.poll()) != null) { + removeLogger(loggerRef); + } + } + + /** + * Removes a logger from the registry. + */ + private void removeLogger(Reference<? extends Logger> loggerRef) { + writeLock.lock(); + try { + loggerRefByNameByMessageFactory.values().forEach(map -> map.values().removeIf(ref -> ref == loggerRef)); + } finally { + writeLock.unlock(); + } + } + /** * Returns the logger associated with the given name and message factory. - * - * @param name a logger name - * @param messageFactory a message factory - * @return the logger associated with the given name and message factory Review Comment: Why do you remove these? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org