ppkarwasz commented on code in PR #3501: URL: https://github.com/apache/logging-log4j2/pull/3501#discussion_r2105212227
########## log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/api/ConfigurationBuilder.java: ########## @@ -61,6 +61,10 @@ public interface ConfigurationBuilder<T extends Configuration> extends Builder<T */ ConfigurationBuilder<T> add(CustomLevelComponentBuilder builder); + default ConfigurationBuilder<T> add(MonitorResourceComponentBuilder builder) { + throw new UnsupportedOperationException(); + } Review Comment: 1. Add a generic method for top-level elements in `ConfigurationBuilder`: ```java ConfigurationBuilder<T> addComponent(ComponentBuilder<?> builder); ``` It mirrors `ComponentBuilder#addComponent`, but uses a distinct name to differentiate from specialized `add` methods. ########## log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java: ########## @@ -124,6 +125,26 @@ public PropertiesConfiguration build() { } } + Properties monitorResources = PropertiesUtil.extractSubset(rootProperties, "monitorResources"); + if (monitorResources.size() > 0) { + final String monitorResourcesType = (String) monitorResources.remove("type"); + if (!"MonitorResources".equals(monitorResourcesType)) { + throw new ConfigurationException( + "No or invalid type provided for monitorResouces - must be MonitorResources"); + } + final Map<String, Properties> monitorResourceMap = + PropertiesUtil.partitionOnCommonPrefixes(monitorResources); + for (final Map.Entry<String, Properties> entry : monitorResourceMap.entrySet()) { + final Properties monitorResourceProps = entry.getValue(); + final String monitorResourceType = (String) monitorResourceProps.remove("type"); + if (!"MonitorResource".equals(monitorResourceType)) { + throw new ConfigurationException( + "No or invalid type provided for monitorResouce - must be MonitorResource"); + } + builder.add(createMonitorResource(entry.getKey().trim(), entry.getValue())); + } + } + Review Comment: 2. Add an overload of `processRemainingProperties` that accepts a `ConfigurationBuilder`: ```java private void processRemainingProperties(ConfigurationBuilder builder, Properties properties); ``` 3. Invoke this new method at the end of the `build()` method, replacing the less generic implementation above. 4. One remaining issue: the `build()` method contains multiple `Properties.getProperty()` calls, which do not remove entries from the `Properties` object. To prevent duplicate processing in `processRemainingProperties`, replace these calls with `Properties.remove()`. -- 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