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


##########
log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java:
##########
@@ -333,6 +334,73 @@ public Configuration getConfiguration(
         return getConfiguration(loggerContext, name, configLocation);
     }
 
+    /**
+     * Creates a Configuration from multiple configuration URIs.
+     * If multiple URIs are successfully loaded, they will be combined into a 
CompositeConfiguration.
+     *
+     * @param loggerContext the logger context (may be null)
+     * @param name the configuration name (may be null)
+     * @param uris the list of configuration URIs (must not be null or empty)
+     * @return a Configuration created from the provided URIs
+     * @throws NullPointerException if uris is null
+     * @throws IllegalArgumentException if uris is empty
+     * @throws ConfigurationException if no valid configuration could be 
created
+     * from any of the provided URIs
+     * @since 2.26.0
+     */
+    public Configuration getConfiguration(final LoggerContext loggerContext, 
final String name, final List<URI> uris) {
+
+        Objects.requireNonNull(uris, "uris parameter cannot be null");
+
+        if (uris.isEmpty()) {
+            throw new IllegalArgumentException("URI list cannot be empty");
+        }
+
+        if (uris.size() == 1) {
+            final Configuration config = getConfiguration(loggerContext, name, 
uris.get(0));
+            if (config == null) {
+                throw new ConfigurationException("Failed to create 
configuration from: " + uris.get(0));
+            }
+            return config;
+        }
+
+        final List<AbstractConfiguration> configurations = new ArrayList<>();
+        final List<URI> failedUris = new ArrayList<>();
+
+        for (final URI uri : uris) {
+            try {
+                final Configuration config = getConfiguration(loggerContext, 
name, uri);
+
+                if (config != null) {
+                    if (config instanceof AbstractConfiguration) {
+                        configurations.add((AbstractConfiguration) config);
+                    } else {
+                        LOGGER.error("Configuration at {} is not an 
AbstractConfiguration", uri);
+                        failedUris.add(uri);

Review Comment:
   I'm in favor of keeping things simple: if `config instanceof AC` fails, 
throw a `ConfigurationException`. This will render `failedUris` booking, 
`config != null` checks, and `catch` at line 385 redundant.



##########
log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java:
##########
@@ -333,6 +334,73 @@ public Configuration getConfiguration(
         return getConfiguration(loggerContext, name, configLocation);
     }
 
+    /**
+     * Creates a Configuration from multiple configuration URIs.
+     * If multiple URIs are successfully loaded, they will be combined into a 
CompositeConfiguration.
+     *
+     * @param loggerContext the logger context (may be null)
+     * @param name the configuration name (may be null)
+     * @param uris the list of configuration URIs (must not be null or empty)
+     * @return a Configuration created from the provided URIs
+     * @throws NullPointerException if uris is null
+     * @throws IllegalArgumentException if uris is empty
+     * @throws ConfigurationException if no valid configuration could be 
created
+     * from any of the provided URIs
+     * @since 2.26.0
+     */
+    public Configuration getConfiguration(final LoggerContext loggerContext, 
final String name, final List<URI> uris) {
+
+        Objects.requireNonNull(uris, "uris parameter cannot be null");
+
+        if (uris.isEmpty()) {
+            throw new IllegalArgumentException("URI list cannot be empty");
+        }
+
+        if (uris.size() == 1) {
+            final Configuration config = getConfiguration(loggerContext, name, 
uris.get(0));
+            if (config == null) {
+                throw new ConfigurationException("Failed to create 
configuration from: " + uris.get(0));
+            }
+            return config;
+        }

Review Comment:
   You don't need this `if` block, it is already handled by
   ```
   return configurations.size() == 1 ? configurations.get(0)
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to