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


##########
log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java:
##########
@@ -1178,4 +1152,28 @@ public NanoClock getNanoClock() {
     public void setNanoClock(final NanoClock nanoClock) {
         instanceFactory.registerBinding(NanoClock.KEY, () -> nanoClock);
     }
+
+    @Override
+    public void addExtension(ConfigurationExtension extension) {
+        Objects.requireNonNull(extension);
+        extensions = Arrays.copyOf(extensions, extensions.length + 1);
+        extensions[extensions.length - 1] = extension;
+    }
+
+    @Override
+    public <T extends ConfigurationExtension> T getExtension(Class<T> 
extensionType) {
+        T result = null;
+        for (final ConfigurationExtension extension : extensions) {
+            if (extensionType.isInstance(extension)) {
+                if (result == null) {
+                    result = (T) extension;
+                } else {
+                    LOGGER.warn(
+                            "Multiple configuration elements found for type 
{}. Only the first will be used.",
+                            extensionType.getName());
+                }
+            }
+        }
+        return result;
+    }

Review Comment:
   My idea behind this is to prevent plugin implementors from abusing this 
feature by adding a lot of new elements to the `<Configuration>` tag.
   
   Let's say an extension wants to add multiple `<Recycler>` elements to a 
configuration. Then I would strongly prefer to put them in a **single** 
`<Recyclers>` wrapper element, instead of polluting the main `<Configuration>` 
element.



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