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


##########
log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java:
##########
@@ -347,6 +349,17 @@ public void start() {
         LOGGER.info("Configuration {} started.", this);
     }
 
+    private void watchMonitorResources() {
+        if (this instanceof Reconfigurable && 
watchManager.getIntervalSeconds() >= 0) {

Review Comment:
   ```suggestion
           if (this instanceof Reconfigurable && 
watchManager.getIntervalSeconds() > 0) {
   ```
   
   If `monitorInterval` is `0`, monitoring is disabled.



##########
log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java:
##########
@@ -325,7 +327,7 @@ public void start() {
         if (watchManager.getIntervalSeconds() >= 0) {
             LOGGER.info(
                     "Start watching for changes to {} every {} seconds",
-                    getConfigurationSource(),
+                    watchManager.getConfigurationWatchers().keySet(),

Review Comment:
   Can we use the same condition as on line 353?



##########
log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java:
##########
@@ -124,6 +125,12 @@ public PropertiesConfiguration build() {
             }
         }
 
+        final Map<String, Properties> monitorResources = 
PropertiesUtil.partitionOnCommonPrefixes(
+                PropertiesUtil.extractSubset(rootProperties, 
"monitorResources"));
+        for (final Map.Entry<String, Properties> entry : 
monitorResources.entrySet()) {
+            builder.add(createMonitorResource(entry.getKey().trim(), 
entry.getValue()));
+        }

Review Comment:
   I'm not sure this is the right approach for introducing a new global element 
to the `log4j2.properties` configuration format.
   
   The format follows a consistent pattern for defining components under a 
parent element:  
   - To add a subcomponent, you define a property in the form of `<parent 
prefix>.<unique id>.type`, with the value set to the Log4j plugin name of the 
subcomponent. For example, in this case:
     ```properties
     monitorResources.type = MonitorResources
     ```
   
   Allowing users to omit the `monitorResources.type` property would add 
another exception to the configuration format—which is already full of quirks 
and exceptions, as documented in [Java properties format 
quirks](https://logging.apache.org/log4j/2.x/manual/configuration.html#java-properties-features).
 Since version 3.x aims to remove all such quirks, introducing a new one now 
would lead to a future breaking change.
   



##########
log4j-core/src/main/java/org/apache/logging/log4j/core/config/MonitorResource.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.core.config;
+
+import static java.util.Objects.requireNonNull;
+
+import java.net.URI;
+import org.apache.logging.log4j.core.Core;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+
+/**
+ * Container for the {@code MonitorResource} element.
+ */
+@Plugin(name = "MonitorResource", category = Core.CATEGORY_NAME, printObject = 
true)
+public final class MonitorResource {
+
+    private final URI uri;
+
+    private MonitorResource(final URI uri) {
+        this.uri = requireNonNull(uri, "uri");
+        if (!"file".equals(uri.getScheme())) {
+            final String message =
+                    String.format("Only `file` scheme is supported in monitor 
resource URIs! Illegal URI: `%s`", uri);
+            throw new IllegalArgumentException(message);
+        }
+    }
+
+    @PluginFactory
+    public static MonitorResource 
createMonitorResource(@PluginAttribute("uri") final URI uri) {

Review Comment:
   If we anticipate adding more attributes to `MonitorResource` in the future, 
it would be more maintainable to adopt the builder pattern here.
   
   However, if MonitorResource is unlikely to change further, then simply 
adding the `uris` attribute directly to `MonitorResources` should suffice.



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