You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2023/11/13 20:15:58 UTC

(logging-log4j2) branch main updated (def47a8f82 -> 61d3e703e4)

This is an automated email from the ASF dual-hosted git repository.

mattsicker pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


    from def47a8f82 Fix `FileOutputTest` on Windows
     new c16cba9438 Inline ConfigurableInstanceFactoryPostProcessor::getPostProcessors
     new 61d3e703e4 Update AbstractManager reflective cleanup

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../log4j/core/appender/ReconfigureAppenderTest.java  | 13 +++++--------
 .../java/org/apache/logging/log4j/plugins/di/DI.java  | 12 ++++++++++--
 .../spi/ConfigurableInstanceFactoryPostProcessor.java | 19 +------------------
 3 files changed, 16 insertions(+), 28 deletions(-)


(logging-log4j2) 01/02: Inline ConfigurableInstanceFactoryPostProcessor::getPostProcessors

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mattsicker pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit c16cba94380266238bcde749b0422ac201aeb07d
Author: Matt Sicker <ma...@apache.org>
AuthorDate: Sun Nov 12 18:46:41 2023 -0600

    Inline ConfigurableInstanceFactoryPostProcessor::getPostProcessors
    
    Signed-off-by: Matt Sicker <ma...@apache.org>
---
 .../java/org/apache/logging/log4j/plugins/di/DI.java  | 12 ++++++++++--
 .../spi/ConfigurableInstanceFactoryPostProcessor.java | 19 +------------------
 2 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/DI.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/DI.java
index 91515c38e5..f831f3d262 100644
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/DI.java
+++ b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/DI.java
@@ -16,7 +16,12 @@
  */
 package org.apache.logging.log4j.plugins.di;
 
+import java.lang.invoke.MethodHandles;
+import java.util.Comparator;
+
 import org.apache.logging.log4j.plugins.di.spi.ConfigurableInstanceFactoryPostProcessor;
+import org.apache.logging.log4j.plugins.util.OrderedComparator;
+import org.apache.logging.log4j.util.ServiceRegistry;
 
 /**
  * Factory for {@linkplain InstanceFactory instance factories}.
@@ -70,7 +75,10 @@ public final class DI {
      * @param factory the instance factory to initialize
      */
     public static void initializeFactory(final ConfigurableInstanceFactory factory) {
-        ConfigurableInstanceFactoryPostProcessor.getPostProcessors()
-                .forEach(processor -> processor.postProcessFactory(factory));
+        ServiceRegistry.getInstance()
+                .getServices(ConfigurableInstanceFactoryPostProcessor.class, MethodHandles.lookup(), null)
+                .stream()
+                .sorted(Comparator.comparing(ConfigurableInstanceFactoryPostProcessor::getClass, OrderedComparator.INSTANCE))
+                .forEachOrdered(processor -> processor.postProcessFactory(factory));
     }
 }
diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/spi/ConfigurableInstanceFactoryPostProcessor.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/spi/ConfigurableInstanceFactoryPostProcessor.java
index 478e66518d..5b0dc08454 100644
--- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/spi/ConfigurableInstanceFactoryPostProcessor.java
+++ b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/spi/ConfigurableInstanceFactoryPostProcessor.java
@@ -16,17 +16,11 @@
  */
 package org.apache.logging.log4j.plugins.di.spi;
 
-import java.lang.invoke.MethodHandles;
-import java.util.Comparator;
-import java.util.List;
 import java.util.ServiceLoader;
 
-import aQute.bnd.annotation.Resolution;
 import aQute.bnd.annotation.spi.ServiceConsumer;
 import org.apache.logging.log4j.plugins.Ordered;
 import org.apache.logging.log4j.plugins.di.ConfigurableInstanceFactory;
-import org.apache.logging.log4j.plugins.util.OrderedComparator;
-import org.apache.logging.log4j.util.ServiceRegistry;
 
 /**
  * Provides post-processing capabilities to the initialization of a {@link ConfigurableInstanceFactory}.
@@ -34,7 +28,7 @@ import org.apache.logging.log4j.util.ServiceRegistry;
  * {@link Ordered} annotation on the class for overriding the order it will be invoked.
  */
 @FunctionalInterface
-@ServiceConsumer(value = ConfigurableInstanceFactoryPostProcessor.class, resolution = Resolution.OPTIONAL)
+@ServiceConsumer(ConfigurableInstanceFactoryPostProcessor.class)
 public interface ConfigurableInstanceFactoryPostProcessor {
 
     /**
@@ -44,15 +38,4 @@ public interface ConfigurableInstanceFactoryPostProcessor {
      */
     void postProcessFactory(final ConfigurableInstanceFactory factory);
 
-    /**
-     * Gets the list of registered post processor services and sorts them using {@link OrderedComparator}.
-     *
-     * @return list of post processor services
-     */
-    static List<ConfigurableInstanceFactoryPostProcessor> getPostProcessors() {
-        final List<ConfigurableInstanceFactoryPostProcessor> services = ServiceRegistry.getInstance()
-                .getServices(ConfigurableInstanceFactoryPostProcessor.class, MethodHandles.lookup(), null);
-        services.sort(Comparator.comparing(ConfigurableInstanceFactoryPostProcessor::getClass, OrderedComparator.INSTANCE));
-        return services;
-    }
 }


(logging-log4j2) 02/02: Update AbstractManager reflective cleanup

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mattsicker pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 61d3e703e481efa3705eb9e7f38710b322cc17fe
Author: Matt Sicker <ma...@apache.org>
AuthorDate: Sun Nov 12 18:48:45 2023 -0600

    Update AbstractManager reflective cleanup
    
    This was matching the old behavior which changed.
    
    Signed-off-by: Matt Sicker <ma...@apache.org>
---
 .../log4j/core/appender/ReconfigureAppenderTest.java        | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/ReconfigureAppenderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/ReconfigureAppenderTest.java
index 6f96ab4b7b..dcc03e1bae 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/ReconfigureAppenderTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/ReconfigureAppenderTest.java
@@ -17,13 +17,13 @@
 package org.apache.logging.log4j.core.appender;
 
 import java.lang.reflect.Field;
-import java.util.Map;
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.core.Logger;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.appender.rolling.DirectWriteRolloverStrategy;
+import org.apache.logging.log4j.core.appender.rolling.RollingFileManager;
 import org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy;
 import org.apache.logging.log4j.core.config.Configurator;
 import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
@@ -105,15 +105,12 @@ public class ReconfigureAppenderTest {
     {
         try
         {
-            final Field field = AbstractManager.class.getDeclaredField("MAP");
+            final Field field = AbstractManager.class.getDeclaredField("REGISTRY");
             field.setAccessible(true);
+            final ManagerRegistry registry = (ManagerRegistry) field.get(null);
 
-            // Retrieve the map itself.
-            final Map<String, AbstractManager> map =
-            (Map<String, AbstractManager>) field.get(null);
-
-            // Remove the file manager keyed on file pattern.
-            map.remove(appender.getFilePattern());
+            final RollingFileManager manager = appender.getManager();
+            registry.removeManager(manager.getName(), manager);
         }
         catch (Exception e)
         {