You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2022/01/10 22:25:23 UTC

[logging-log4j2] branch master updated (e67c981 -> 39f3e23)

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

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


    from e67c981  Clean up and bullet-proof H2 and HSQLDB tests.
     new 73dfb01  Fix compilation failure.
     new 7d6acd6  Sort members.
     new 39f3e23  Log4j 1.2 bridge missing OptionConverter.instantiateByKey(Properties, String, Class, Object).

The 3 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:
 .../org/apache/log4j/helpers/OptionConverter.java  | 518 +++++++++++----------
 .../log4j/config/PropertiesConfigurationTest.java  |   2 -
 2 files changed, 265 insertions(+), 255 deletions(-)

[logging-log4j2] 01/03: Fix compilation failure.

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

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

commit 73dfb01a8d112a6df0f2ee194e50b5af80e2c987
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jan 10 17:21:59 2022 -0500

    Fix compilation failure.
---
 .../test/java/org/apache/log4j/config/PropertiesConfigurationTest.java  | 2 --
 1 file changed, 2 deletions(-)

diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesConfigurationTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesConfigurationTest.java
index 21792e5..48bf528 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesConfigurationTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesConfigurationTest.java
@@ -36,7 +36,6 @@ import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.appender.FileAppender;
 import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.plugins.util.PluginManager;
 import org.apache.logging.log4j.core.filter.CompositeFilter;
 import org.apache.logging.log4j.core.filter.Filterable;
 import org.apache.logging.log4j.core.filter.LevelRangeFilter;
@@ -92,7 +91,6 @@ public class PropertiesConfigurationTest {
     
     @Test
     public void testConsoleAppenderLevelRangeFilter() throws Exception {
-        PluginManager.addPackage("org.apache.log4j.builders.filter");
         try (LoggerContext loggerContext = TestConfigurator.configure("target/test-classes/LOG4J2-3326.properties")) {
             final Configuration configuration = loggerContext.getConfiguration();
             assertNotNull(configuration);

[logging-log4j2] 02/03: Sort members.

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

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

commit 7d6acd67f469b10819e536add6cc2ad7a0014f91
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jan 10 17:22:04 2022 -0500

    Sort members.
---
 .../org/apache/log4j/helpers/OptionConverter.java  | 506 ++++++++++-----------
 1 file changed, 253 insertions(+), 253 deletions(-)

diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java b/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java
index bcb4d76..fec8186 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java
@@ -41,11 +41,21 @@ import java.util.Properties;
  */
 public class OptionConverter {
 
+    private static class CharMap {
+        final char key;
+        final char replacement;
+
+        public CharMap(char key, char replacement) {
+            this.key = key;
+            this.replacement = replacement;
+        }
+    }
     static String DELIM_START = "${";
     static char DELIM_STOP = '}';
     static int DELIM_START_LEN = 2;
     static int DELIM_STOP_LEN = 1;
     private static final Logger LOGGER = LogManager.getLogger(OptionConverter.class);
+
     private static final CharMap[] charMap = new CharMap[] {
             new CharMap('n', '\n'),
             new CharMap('r', '\r'),
@@ -57,12 +67,6 @@ public class OptionConverter {
             new CharMap('\\', '\\')
     };
 
-    /**
-     * OptionConverter is a static class.
-     */
-    private OptionConverter() {
-    }
-
     public static String[] concatanateArrays(String[] l, String[] r) {
         int len = l.length + r.length;
         String[] a = new String[len];
@@ -73,6 +77,57 @@ public class OptionConverter {
         return a;
     }
 
+    public static  org.apache.logging.log4j.Level convertLevel(Level level) {
+        if (level == null) {
+            return org.apache.logging.log4j.Level.ERROR;
+        }
+        if (level.isGreaterOrEqual(Level.FATAL)) {
+            return org.apache.logging.log4j.Level.FATAL;
+        } else if (level.isGreaterOrEqual(Level.ERROR)) {
+            return org.apache.logging.log4j.Level.ERROR;
+        } else if (level.isGreaterOrEqual(Level.WARN)) {
+            return org.apache.logging.log4j.Level.WARN;
+        } else if (level.isGreaterOrEqual(Level.INFO)) {
+            return org.apache.logging.log4j.Level.INFO;
+        } else if (level.isGreaterOrEqual(Level.DEBUG)) {
+            return org.apache.logging.log4j.Level.DEBUG;
+        } else if (level.isGreaterOrEqual(Level.TRACE)) {
+            return org.apache.logging.log4j.Level.TRACE;
+        }
+        return org.apache.logging.log4j.Level.ALL;
+    }
+
+
+    public static Level convertLevel(org.apache.logging.log4j.Level level) {
+        if (level == null) {
+            return Level.ERROR;
+        }
+        switch (level.getStandardLevel()) {
+            case FATAL:
+                return Level.FATAL;
+            case WARN:
+                return Level.WARN;
+            case INFO:
+                return Level.INFO;
+            case DEBUG:
+                return Level.DEBUG;
+            case TRACE:
+                return Level.TRACE;
+            case ALL:
+                return Level.ALL;
+            case OFF:
+                return Level.OFF;
+            default:
+                return Level.ERROR;
+        }
+    }
+
+    public static org.apache.logging.log4j.Level convertLevel(String level,
+            org.apache.logging.log4j.Level defaultLevel) {
+        Level l = toLevel(level, null);
+        return l != null ? convertLevel(l) : defaultLevel;
+    }
+
     public static String convertSpecialChars(String s) {
         char c;
         int len = s.length();
@@ -94,6 +149,28 @@ public class OptionConverter {
         return sbuf.toString();
     }
 
+    /**
+     * Find the value corresponding to <code>key</code> in
+     * <code>props</code>. Then perform variable substitution on the
+     * found value.
+     * @param key The key used to locate the substitution string.
+     * @param props The properties to use in the substitution.
+     * @return The substituted string.
+     */
+    public static String findAndSubst(String key, Properties props) {
+        String value = props.getProperty(key);
+        if (value == null) {
+            return null;
+        }
+
+        try {
+            return substVars(value, props);
+        } catch (IllegalArgumentException e) {
+            LOGGER.error("Bad option value [{}].", value, e);
+            return value;
+        }
+    }
+
 
     /**
      * Very similar to <code>System.getProperty</code> except
@@ -115,123 +192,6 @@ public class OptionConverter {
     }
 
     /**
-     * If <code>value</code> is "true", then <code>true</code> is
-     * returned. If <code>value</code> is "false", then
-     * <code>true</code> is returned. Otherwise, <code>default</code> is
-     * returned.
-     *
-     * <p>Case of value is unimportant.
-     * @param value The value to convert.
-     * @param dEfault The default value.
-     * @return the value of the result.
-     */
-    public static boolean toBoolean(String value, boolean dEfault) {
-        if (value == null) {
-            return dEfault;
-        }
-        String trimmedVal = value.trim();
-        if ("true".equalsIgnoreCase(trimmedVal)) {
-            return true;
-        }
-        if ("false".equalsIgnoreCase(trimmedVal)) {
-            return false;
-        }
-        return dEfault;
-    }
-
-    /**
-     * Converts a standard or custom priority level to a Level
-     * object.  <p> If <code>value</code> is of form
-     * "level#classname", then the specified class' toLevel method
-     * is called to process the specified level string; if no '#'
-     * character is present, then the default {@link org.apache.log4j.Level}
-     * class is used to process the level value.
-     *
-     * <p>As a special case, if the <code>value</code> parameter is
-     * equal to the string "NULL", then the value <code>null</code> will
-     * be returned.
-     *
-     * <p> If any error occurs while converting the value to a level,
-     * the <code>defaultValue</code> parameter, which may be
-     * <code>null</code>, is returned.
-     *
-     * <p> Case of <code>value</code> is insignificant for the level level, but is
-     * significant for the class name part, if present.
-     * @param value The value to convert.
-     * @param defaultValue The default value.
-     * @return the value of the result.
-     *
-     * @since 1.1
-     */
-    public static Level toLevel(String value, Level defaultValue) {
-        if (value == null) {
-            return defaultValue;
-        }
-
-        value = value.trim();
-
-        int hashIndex = value.indexOf('#');
-        if (hashIndex == -1) {
-            if ("NULL".equalsIgnoreCase(value)) {
-                return null;
-            }
-            // no class name specified : use standard Level class
-            return Level.toLevel(value, defaultValue);
-        }
-
-        Level result = defaultValue;
-
-        String clazz = value.substring(hashIndex + 1);
-        String levelName = value.substring(0, hashIndex);
-
-        // This is degenerate case but you never know.
-        if ("NULL".equalsIgnoreCase(levelName)) {
-            return null;
-        }
-
-        LOGGER.debug("toLevel" + ":class=[" + clazz + "]"
-                + ":pri=[" + levelName + "]");
-
-        try {
-            Class<?> customLevel = LoaderUtil.loadClass(clazz);
-
-            // get a ref to the specified class' static method
-            // toLevel(String, org.apache.log4j.Level)
-            Class<?>[] paramTypes = new Class[] { String.class, org.apache.log4j.Level.class };
-            java.lang.reflect.Method toLevelMethod =
-                    customLevel.getMethod("toLevel", paramTypes);
-
-            // now call the toLevel method, passing level string + default
-            Object[] params = new Object[]{levelName, defaultValue};
-            Object o = toLevelMethod.invoke(null, params);
-
-            result = (Level) o;
-        } catch (ClassNotFoundException e) {
-            LOGGER.warn("custom level class [" + clazz + "] not found.");
-        } catch (NoSuchMethodException e) {
-            LOGGER.warn("custom level class [" + clazz + "]"
-                    + " does not have a class function toLevel(String, Level)", e);
-        } catch (java.lang.reflect.InvocationTargetException e) {
-            if (e.getTargetException() instanceof InterruptedException
-                    || e.getTargetException() instanceof InterruptedIOException) {
-                Thread.currentThread().interrupt();
-            }
-            LOGGER.warn("custom level class [" + clazz + "]"
-                    + " could not be instantiated", e);
-        } catch (ClassCastException e) {
-            LOGGER.warn("class [" + clazz
-                    + "] is not a subclass of org.apache.log4j.Level", e);
-        } catch (IllegalAccessException e) {
-            LOGGER.warn("class [" + clazz +
-                    "] cannot be instantiated due to access restrictions", e);
-        } catch (RuntimeException e) {
-            LOGGER.warn("class [" + clazz + "], level [" + levelName +
-                    "] conversion failed.", e);
-        }
-        return result;
-    }
-
-    /**
      * Instantiate an object given a class name. Check that the
      * <code>className</code> is a subclass of
      * <code>superClass</code>. If that test fails or the object could
@@ -261,6 +221,78 @@ public class OptionConverter {
         return defaultValue;
     }
 
+    /**
+     * Configure log4j given an {@link InputStream}.
+     * <p>
+     * The InputStream will be interpreted by a new instance of a log4j configurator.
+     * </p>
+     * <p>
+     * All configurations steps are taken on the <code>hierarchy</code> passed as a parameter.
+     * </p>
+     *
+     * @param inputStream The configuration input stream.
+     * @param clazz The class name, of the log4j configurator which will parse the <code>inputStream</code>. This must be a
+     *        subclass of {@link Configurator}, or null. If this value is null then a default configurator of
+     *        {@link PropertyConfigurator} is used.
+     * @param hierarchy The {@link LoggerRepository} to act on.
+     * @since 1.2.17
+     */
+    static public void selectAndConfigure(InputStream inputStream, String clazz, LoggerRepository hierarchy) {
+        Configurator configurator = null;
+
+        if (clazz != null) {
+            LOGGER.debug("Preferred configurator class: " + clazz);
+            configurator = (Configurator) instantiateByClassName(clazz, Configurator.class, null);
+            if (configurator == null) {
+                LOGGER.error("Could not instantiate configurator [" + clazz + "].");
+                return;
+            }
+        } else {
+            configurator = new PropertyConfigurator();
+        }
+
+        configurator.doConfigure(inputStream, hierarchy);
+    }
+
+    /**
+     * Configure log4j given a URL.
+     * <p>
+     * The url must point to a file or resource which will be interpreted by a new instance of a log4j configurator.
+     * </p>
+     * <p>
+     * All configurations steps are taken on the <code>hierarchy</code> passed as a parameter.
+     * </p>
+     *
+     * @param url The location of the configuration file or resource.
+     * @param clazz The classname, of the log4j configurator which will parse the file or resource at <code>url</code>. This
+     *        must be a subclass of {@link Configurator}, or null. If this value is null then a default configurator of
+     *        {@link PropertyConfigurator} is used, unless the filename pointed to by <code>url</code> ends in '.xml', in
+     *        which case {@link org.apache.log4j.xml.DOMConfigurator} is used.
+     * @param hierarchy The {@link LoggerRepository} to act on.
+     *
+     * @since 1.1.4
+     */
+    static public void selectAndConfigure(URL url, String clazz, LoggerRepository hierarchy) {
+        Configurator configurator = null;
+        String filename = url.getFile();
+
+        if (clazz == null && filename != null && filename.endsWith(".xml")) {
+            clazz = "org.apache.log4j.xml.DOMConfigurator";
+        }
+
+        if (clazz != null) {
+            LOGGER.debug("Preferred configurator class: " + clazz);
+            configurator = (Configurator) instantiateByClassName(clazz, Configurator.class, null);
+            if (configurator == null) {
+                LOGGER.error("Could not instantiate configurator [" + clazz + "].");
+                return;
+            }
+        } else {
+            configurator = new PropertyConfigurator();
+        }
+
+        configurator.doConfigure(url, hierarchy);
+    }
 
     /**
      * Perform variable substitution in string <code>val</code> from the
@@ -360,158 +392,126 @@ public class OptionConverter {
         }
     }
 
-    public static org.apache.logging.log4j.Level convertLevel(String level,
-            org.apache.logging.log4j.Level defaultLevel) {
-        Level l = toLevel(level, null);
-        return l != null ? convertLevel(l) : defaultLevel;
-    }
-
-    public static  org.apache.logging.log4j.Level convertLevel(Level level) {
-        if (level == null) {
-            return org.apache.logging.log4j.Level.ERROR;
-        }
-        if (level.isGreaterOrEqual(Level.FATAL)) {
-            return org.apache.logging.log4j.Level.FATAL;
-        } else if (level.isGreaterOrEqual(Level.ERROR)) {
-            return org.apache.logging.log4j.Level.ERROR;
-        } else if (level.isGreaterOrEqual(Level.WARN)) {
-            return org.apache.logging.log4j.Level.WARN;
-        } else if (level.isGreaterOrEqual(Level.INFO)) {
-            return org.apache.logging.log4j.Level.INFO;
-        } else if (level.isGreaterOrEqual(Level.DEBUG)) {
-            return org.apache.logging.log4j.Level.DEBUG;
-        } else if (level.isGreaterOrEqual(Level.TRACE)) {
-            return org.apache.logging.log4j.Level.TRACE;
-        }
-        return org.apache.logging.log4j.Level.ALL;
-    }
-
-    public static Level convertLevel(org.apache.logging.log4j.Level level) {
-        if (level == null) {
-            return Level.ERROR;
-        }
-        switch (level.getStandardLevel()) {
-            case FATAL:
-                return Level.FATAL;
-            case WARN:
-                return Level.WARN;
-            case INFO:
-                return Level.INFO;
-            case DEBUG:
-                return Level.DEBUG;
-            case TRACE:
-                return Level.TRACE;
-            case ALL:
-                return Level.ALL;
-            case OFF:
-                return Level.OFF;
-            default:
-                return Level.ERROR;
-        }
-    }
-
     /**
-     * Configure log4j given an {@link InputStream}.
-     * <p>
-     * The InputStream will be interpreted by a new instance of a log4j configurator.
-     * </p>
-     * <p>
-     * All configurations steps are taken on the <code>hierarchy</code> passed as a parameter.
-     * </p>
+     * If <code>value</code> is "true", then <code>true</code> is
+     * returned. If <code>value</code> is "false", then
+     * <code>true</code> is returned. Otherwise, <code>default</code> is
+     * returned.
      *
-     * @param inputStream The configuration input stream.
-     * @param clazz The class name, of the log4j configurator which will parse the <code>inputStream</code>. This must be a
-     *        subclass of {@link Configurator}, or null. If this value is null then a default configurator of
-     *        {@link PropertyConfigurator} is used.
-     * @param hierarchy The {@link LoggerRepository} to act on.
-     * @since 1.2.17
+     * <p>Case of value is unimportant.
+     * @param value The value to convert.
+     * @param dEfault The default value.
+     * @return the value of the result.
      */
-    static public void selectAndConfigure(InputStream inputStream, String clazz, LoggerRepository hierarchy) {
-        Configurator configurator = null;
-
-        if (clazz != null) {
-            LOGGER.debug("Preferred configurator class: " + clazz);
-            configurator = (Configurator) instantiateByClassName(clazz, Configurator.class, null);
-            if (configurator == null) {
-                LOGGER.error("Could not instantiate configurator [" + clazz + "].");
-                return;
-            }
-        } else {
-            configurator = new PropertyConfigurator();
+    public static boolean toBoolean(String value, boolean dEfault) {
+        if (value == null) {
+            return dEfault;
         }
-
-        configurator.doConfigure(inputStream, hierarchy);
+        String trimmedVal = value.trim();
+        if ("true".equalsIgnoreCase(trimmedVal)) {
+            return true;
+        }
+        if ("false".equalsIgnoreCase(trimmedVal)) {
+            return false;
+        }
+        return dEfault;
     }
 
     /**
-     * Configure log4j given a URL.
-     * <p>
-     * The url must point to a file or resource which will be interpreted by a new instance of a log4j configurator.
-     * </p>
-     * <p>
-     * All configurations steps are taken on the <code>hierarchy</code> passed as a parameter.
-     * </p>
+     * Converts a standard or custom priority level to a Level
+     * object.  <p> If <code>value</code> is of form
+     * "level#classname", then the specified class' toLevel method
+     * is called to process the specified level string; if no '#'
+     * character is present, then the default {@link org.apache.log4j.Level}
+     * class is used to process the level value.
      *
-     * @param url The location of the configuration file or resource.
-     * @param clazz The classname, of the log4j configurator which will parse the file or resource at <code>url</code>. This
-     *        must be a subclass of {@link Configurator}, or null. If this value is null then a default configurator of
-     *        {@link PropertyConfigurator} is used, unless the filename pointed to by <code>url</code> ends in '.xml', in
-     *        which case {@link org.apache.log4j.xml.DOMConfigurator} is used.
-     * @param hierarchy The {@link LoggerRepository} to act on.
+     * <p>As a special case, if the <code>value</code> parameter is
+     * equal to the string "NULL", then the value <code>null</code> will
+     * be returned.
      *
-     * @since 1.1.4
+     * <p> If any error occurs while converting the value to a level,
+     * the <code>defaultValue</code> parameter, which may be
+     * <code>null</code>, is returned.
+     *
+     * <p> Case of <code>value</code> is insignificant for the level level, but is
+     * significant for the class name part, if present.
+     * @param value The value to convert.
+     * @param defaultValue The default value.
+     * @return the value of the result.
+     *
+     * @since 1.1
      */
-    static public void selectAndConfigure(URL url, String clazz, LoggerRepository hierarchy) {
-        Configurator configurator = null;
-        String filename = url.getFile();
-
-        if (clazz == null && filename != null && filename.endsWith(".xml")) {
-            clazz = "org.apache.log4j.xml.DOMConfigurator";
+    public static Level toLevel(String value, Level defaultValue) {
+        if (value == null) {
+            return defaultValue;
         }
 
-        if (clazz != null) {
-            LOGGER.debug("Preferred configurator class: " + clazz);
-            configurator = (Configurator) instantiateByClassName(clazz, Configurator.class, null);
-            if (configurator == null) {
-                LOGGER.error("Could not instantiate configurator [" + clazz + "].");
-                return;
+        value = value.trim();
+
+        int hashIndex = value.indexOf('#');
+        if (hashIndex == -1) {
+            if ("NULL".equalsIgnoreCase(value)) {
+                return null;
             }
-        } else {
-            configurator = new PropertyConfigurator();
+            // no class name specified : use standard Level class
+            return Level.toLevel(value, defaultValue);
         }
 
-        configurator.doConfigure(url, hierarchy);
-    }
+        Level result = defaultValue;
 
-    /**
-     * Find the value corresponding to <code>key</code> in
-     * <code>props</code>. Then perform variable substitution on the
-     * found value.
-     * @param key The key used to locate the substitution string.
-     * @param props The properties to use in the substitution.
-     * @return The substituted string.
-     */
-    public static String findAndSubst(String key, Properties props) {
-        String value = props.getProperty(key);
-        if (value == null) {
+        String clazz = value.substring(hashIndex + 1);
+        String levelName = value.substring(0, hashIndex);
+
+        // This is degenerate case but you never know.
+        if ("NULL".equalsIgnoreCase(levelName)) {
             return null;
         }
 
+        LOGGER.debug("toLevel" + ":class=[" + clazz + "]"
+                + ":pri=[" + levelName + "]");
+
         try {
-            return substVars(value, props);
-        } catch (IllegalArgumentException e) {
-            LOGGER.error("Bad option value [{}].", value, e);
-            return value;
-        }
-    }
+            Class<?> customLevel = LoaderUtil.loadClass(clazz);
 
-    private static class CharMap {
-        final char key;
-        final char replacement;
+            // get a ref to the specified class' static method
+            // toLevel(String, org.apache.log4j.Level)
+            Class<?>[] paramTypes = new Class[] { String.class, org.apache.log4j.Level.class };
+            java.lang.reflect.Method toLevelMethod =
+                    customLevel.getMethod("toLevel", paramTypes);
 
-        public CharMap(char key, char replacement) {
-            this.key = key;
-            this.replacement = replacement;
+            // now call the toLevel method, passing level string + default
+            Object[] params = new Object[]{levelName, defaultValue};
+            Object o = toLevelMethod.invoke(null, params);
+
+            result = (Level) o;
+        } catch (ClassNotFoundException e) {
+            LOGGER.warn("custom level class [" + clazz + "] not found.");
+        } catch (NoSuchMethodException e) {
+            LOGGER.warn("custom level class [" + clazz + "]"
+                    + " does not have a class function toLevel(String, Level)", e);
+        } catch (java.lang.reflect.InvocationTargetException e) {
+            if (e.getTargetException() instanceof InterruptedException
+                    || e.getTargetException() instanceof InterruptedIOException) {
+                Thread.currentThread().interrupt();
+            }
+            LOGGER.warn("custom level class [" + clazz + "]"
+                    + " could not be instantiated", e);
+        } catch (ClassCastException e) {
+            LOGGER.warn("class [" + clazz
+                    + "] is not a subclass of org.apache.log4j.Level", e);
+        } catch (IllegalAccessException e) {
+            LOGGER.warn("class [" + clazz +
+                    "] cannot be instantiated due to access restrictions", e);
+        } catch (RuntimeException e) {
+            LOGGER.warn("class [" + clazz + "], level [" + levelName +
+                    "] conversion failed.", e);
         }
+        return result;
+    }
+
+    /**
+     * OptionConverter is a static class.
+     */
+    private OptionConverter() {
     }
 }

[logging-log4j2] 03/03: Log4j 1.2 bridge missing OptionConverter.instantiateByKey(Properties, String, Class, Object).

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

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

commit 39f3e2397189d347ed9b9ec017152c3eb7303653
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Jan 10 16:31:41 2022 -0500

    Log4j 1.2 bridge missing OptionConverter.instantiateByKey(Properties,
    String, Class, Object).
---
 .../main/java/org/apache/log4j/helpers/OptionConverter.java  | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java b/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java
index fec8186..3090a9d 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/helpers/OptionConverter.java
@@ -221,6 +221,18 @@ public class OptionConverter {
         return defaultValue;
     }
 
+    public static Object instantiateByKey(Properties props, String key, Class superClass, Object defaultValue) {
+
+        // Get the value of the property in string form
+        String className = findAndSubst(key, props);
+        if (className == null) {
+            LogLog.error("Could not find value for key " + key);
+            return defaultValue;
+        }
+        // Trim className to avoid trailing spaces that cause problems.
+        return OptionConverter.instantiateByClassName(className.trim(), superClass, defaultValue);
+    }
+
     /**
      * Configure log4j given an {@link InputStream}.
      * <p>