ramanathan1504 commented on code in PR #4329:
URL: https://github.com/apache/logging-log4j2/pull/4329#discussion_r4082472108


##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/CompositeConfigurationPostConfigureTest.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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 org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.NullAppender;
+import org.apache.logging.log4j.core.config.composite.CompositeConfiguration;
+import org.apache.logging.log4j.core.config.xml.XmlConfiguration;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Verifies that a {@link CompositeConfiguration} invokes {@link 
AbstractConfiguration#postConfigure(Configuration)}
+ * on each of its source configurations, so a custom {@code Configuration} can 
contribute programmatic elements that
+ * the node-level merge cannot capture. Without the hook the merged 
configuration runs only its own
+ * {@code doConfigure()} and a child's programmatic additions are silently 
dropped, on both the initial build and
+ * after a reconfiguration.
+ */

Review Comment:
   ```suggestion
   ```



##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/CompositeConfigurationPostConfigureTest.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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 org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.NullAppender;
+import org.apache.logging.log4j.core.config.composite.CompositeConfiguration;
+import org.apache.logging.log4j.core.config.xml.XmlConfiguration;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Verifies that a {@link CompositeConfiguration} invokes {@link 
AbstractConfiguration#postConfigure(Configuration)}
+ * on each of its source configurations, so a custom {@code Configuration} can 
contribute programmatic elements that
+ * the node-level merge cannot capture. Without the hook the merged 
configuration runs only its own
+ * {@code doConfigure()} and a child's programmatic additions are silently 
dropped, on both the initial build and
+ * after a reconfiguration.
+ */
+public class CompositeConfigurationPostConfigureTest {
+
+    private static final String MARKER = "programmaticMarker";
+
+    private static final byte[] XML = ("<?xml version=\"1.0\" 
encoding=\"UTF-8\"?>\n"
+                    + "<Configuration><Loggers><Root 
level=\"INFO\"/></Loggers></Configuration>\n")
+            .getBytes(StandardCharsets.UTF_8);
+
+    /** A configuration that contributes a programmatic appender through the 
{@code postConfigure} hook. */
+    private static final class ContributingConfiguration extends 
XmlConfiguration {
+        ContributingConfiguration(final LoggerContext ctx, final 
ConfigurationSource source) {
+            super(ctx, source);
+        }
+
+        @Override
+        public void postConfigure(final Configuration target) {
+            if (target.getAppender(MARKER) == null) {
+                target.addAppender(NullAppender.createAppender(MARKER));
+            }
+        }
+    }
+
+    // A stream-backed source has no URI, so 
CompositeConfiguration.reconfigure() reuses the same child
+    // configuration instead of rebuilding it through a ConfigurationFactory; 
this keeps the test free of any
+    // factory registration while still exercising the real reconfigure() path.

Review Comment:
   ```suggestion
   ```



##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/CompositeConfigurationPostConfigureTest.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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 org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.NullAppender;
+import org.apache.logging.log4j.core.config.composite.CompositeConfiguration;
+import org.apache.logging.log4j.core.config.xml.XmlConfiguration;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Verifies that a {@link CompositeConfiguration} invokes {@link 
AbstractConfiguration#postConfigure(Configuration)}
+ * on each of its source configurations, so a custom {@code Configuration} can 
contribute programmatic elements that
+ * the node-level merge cannot capture. Without the hook the merged 
configuration runs only its own
+ * {@code doConfigure()} and a child's programmatic additions are silently 
dropped, on both the initial build and
+ * after a reconfiguration.
+ */
+public class CompositeConfigurationPostConfigureTest {
+
+    private static final String MARKER = "programmaticMarker";
+
+    private static final byte[] XML = ("<?xml version=\"1.0\" 
encoding=\"UTF-8\"?>\n"
+                    + "<Configuration><Loggers><Root 
level=\"INFO\"/></Loggers></Configuration>\n")
+            .getBytes(StandardCharsets.UTF_8);
+
+    /** A configuration that contributes a programmatic appender through the 
{@code postConfigure} hook. */

Review Comment:
   ```suggestion
   ```



##########
src/changelog/.2.x.x/4328_composite_configuration_post_configure.xml:
##########
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns="https://logging.apache.org/xml/ns";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="https://logging.apache.org/xml/ns 
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd";
+       type="fixed">
+  <issue id="4328" 
link="https://github.com/apache/logging-log4j2/issues/4328"/>

Review Comment:
   ```suggestion
     <issue id="4328" 
link="https://github.com/apache/logging-log4j2/issues/4328"/>
     <issue id="4329" 
link="https://github.com/apache/logging-log4j2/pull/4329"/>
   ```



##########
src/changelog/.2.x.x/4328_composite_configuration_post_configure.xml:
##########
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entry xmlns="https://logging.apache.org/xml/ns";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="https://logging.apache.org/xml/ns 
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd";
+       type="fixed">
+  <issue id="4328" 
link="https://github.com/apache/logging-log4j2/issues/4328"/>
+  <description format="asciidoc">Add `AbstractConfiguration.postConfigure()` 
so a custom configuration keeps its programmatic elements inside a 
`CompositeConfiguration`.</description>

Review Comment:
   ```suggestion
     <description format="asciidoc">Add AbstractConfiguration.postConfigure() 
to keep programmatic elements in CompositeConfiguration</description>
   ```



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