vy commented on code in PR #3209:
URL: https://github.com/apache/logging-log4j2/pull/3209#discussion_r1846088474


##########
log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggerRegistry.java:
##########
@@ -243,32 +232,30 @@ public boolean hasLogger(final String name, final Class<? 
extends MessageFactory
      * Registers the provided logger.
      * <b>Logger name and message factory parameters are ignored</b>, those 
will be obtained from the logger instead.
      *
-     * @param name ignored – kept for backward compatibility
-     * @param messageFactory ignored – kept for backward compatibility
+     * @param name a logger name

Review Comment:
   Why do we deviate from the old behavior where `name` and `MF` is extracted 
from the `Logger`?



##########
log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java:
##########
@@ -526,23 +527,22 @@ public Collection<Logger> getLoggers() {
     public Logger getLogger(final String name, final MessageFactory 
messageFactory) {
         final MessageFactory effectiveMessageFactory =
                 messageFactory != null ? messageFactory : 
DEFAULT_MESSAGE_FACTORY;
-        final Logger oldLogger = loggerRegistry.getLogger(name, 
effectiveMessageFactory);
-        if (oldLogger != null) {
-            return oldLogger;
-        }
-        final Logger newLogger = newInstance(name, effectiveMessageFactory);
-        loggerRegistry.putIfAbsent(name, effectiveMessageFactory, newLogger);
-        return loggerRegistry.getLogger(name, effectiveMessageFactory);
+        return loggerRegistry.computeIfAbsent(name, effectiveMessageFactory, 
this::newInstance);
     }
 
     /**
      * Gets the LoggerRegistry.
      *
      * @return the LoggerRegistry.
      * @since 2.17.2
+     * @deprecated since 2.25.0 without a replacement.

Review Comment:
   Shouldn't this be `2.24.2`?



##########
src/changelog/.2.x.x/3143_logger_registry.xml:
##########
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xmlns="https://logging.apache.org/xml/ns";
+       xsi:schemaLocation="https://logging.apache.org/xml/ns 
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd";
+       type="deprecated">

Review Comment:
   ```suggestion
          type="fixed">
   ```



##########
log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java:
##########
@@ -526,23 +527,22 @@ public Collection<Logger> getLoggers() {
     public Logger getLogger(final String name, final MessageFactory 
messageFactory) {
         final MessageFactory effectiveMessageFactory =
                 messageFactory != null ? messageFactory : 
DEFAULT_MESSAGE_FACTORY;
-        final Logger oldLogger = loggerRegistry.getLogger(name, 
effectiveMessageFactory);
-        if (oldLogger != null) {
-            return oldLogger;
-        }
-        final Logger newLogger = newInstance(name, effectiveMessageFactory);
-        loggerRegistry.putIfAbsent(name, effectiveMessageFactory, newLogger);
-        return loggerRegistry.getLogger(name, effectiveMessageFactory);
+        return loggerRegistry.computeIfAbsent(name, effectiveMessageFactory, 
this::newInstance);
     }
 
     /**
      * Gets the LoggerRegistry.
      *
      * @return the LoggerRegistry.
      * @since 2.17.2
+     * @deprecated since 2.25.0 without a replacement.
      */
-    public LoggerRegistry<Logger> getLoggerRegistry() {
-        return loggerRegistry;
+    @Deprecated
+    public org.apache.logging.log4j.spi.LoggerRegistry<Logger> 
getLoggerRegistry() {
+        org.apache.logging.log4j.spi.LoggerRegistry<Logger> result =
+                new org.apache.logging.log4j.spi.LoggerRegistry<>();
+        loggerRegistry.getLoggers().forEach(l -> 
result.putIfAbsent(l.getName(), l.getMessageFactory(), l));
+        return result;

Review Comment:
   Why do we reconstruct an `LR`? Why don't we simply do a `return 
loggerRegistry`?



-- 
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

Reply via email to