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


##########
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:
   To return `loggerRegistry`, the `InternalLoggerRegistry` class would need to 
extend `o.a.l.l.spi.LoggerRegistry` and reimplement many useless methods.
   
   Since `LoggerContext.getLoggerRegistry()` is only used by `log4j-1.2-api` in 
`LogManager.getCurrentLoggers()`, I prefer to convert `InternalLoggerRegistry` 
into `o.a.l.l.spi.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