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/11 20:22:11 UTC

[logging-log4j2] branch master updated (06bc67a -> d9a835d)

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 06bc67a  Use try-with-resources.
     new e969b66  Use final and better local variable names.
     new 87ceafb  Javadoc.
     new d9a835d  Fix Javadoc.

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:
 .../log4j/config/PropertiesConfiguration.java      | 101 ++++++++++-----------
 .../org/apache/logging/log4j/core/util/Source.java |  24 +++--
 2 files changed, 61 insertions(+), 64 deletions(-)

[logging-log4j2] 02/03: Javadoc.

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 87ceafb562757f78c2e4d1104b2abdac50fe6232
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jan 11 15:04:35 2022 -0500

    Javadoc.
---
 .../main/java/org/apache/logging/log4j/core/util/Source.java | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Source.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Source.java
index a870209..717668f 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Source.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Source.java
@@ -24,14 +24,10 @@ import java.net.URI;
 import java.util.Objects;
 
 /**
- * Represents the source for the logging configuration.
+ * Represents the source for the logging configuration as an immutable object.
  */
 public class Source {
 
-    /**
-     * Captures a URI or File.
-     */
-
     private final File file;
     private final URI uri;
     private final String location;
@@ -70,7 +66,7 @@ public class Source {
     }
 
     /**
-     * Returns the file configuration source, or {@code null} if this configuration source is based on an URL or has
+     * Gets the file configuration source, or {@code null} if this configuration source is based on an URL or has
      * neither a file nor an URL.
      *
      * @return the configuration source file, or {@code null}
@@ -80,7 +76,7 @@ public class Source {
     }
 
     /**
-     * Returns the configuration source URL, or {@code null} if this configuration source is based on a file or has
+     * Gets the configuration source URL, or {@code null} if this configuration source is based on a file or has
      * neither a file nor an URL.
      *
      * @return the configuration source URL, or {@code null}
@@ -90,7 +86,7 @@ public class Source {
     }
 
     /**
-     * Returns a string describing the configuration source file or URL, or {@code null} if this configuration source
+     * Gets a string describing the configuration source file or URL, or {@code null} if this configuration source
      * has neither a file nor an URL.
      *
      * @return a string describing the configuration source file or URL, or {@code null}

[logging-log4j2] 01/03: Use final and better local variable names.

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 e969b6628cd393372b00d3e5c1d61a8d4395df7b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jan 11 15:04:22 2022 -0500

    Use final and better local variable names.
---
 .../log4j/config/PropertiesConfiguration.java      | 101 ++++++++++-----------
 1 file changed, 50 insertions(+), 51 deletions(-)

diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/config/PropertiesConfiguration.java b/log4j-1.2-api/src/main/java/org/apache/log4j/config/PropertiesConfiguration.java
index e26c428..f2740dd 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/config/PropertiesConfiguration.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/config/PropertiesConfiguration.java
@@ -90,22 +90,22 @@ public class PropertiesConfiguration extends Log4j1Configuration {
      * @param monitorIntervalSeconds The monitoring interval in seconds.
      */
     public PropertiesConfiguration(final LoggerContext loggerContext, final ConfigurationSource source,
-            int monitorIntervalSeconds) {
+            final int monitorIntervalSeconds) {
         super(loggerContext, source, monitorIntervalSeconds);
     }
 
     @Override
     public void doConfigure() {
-        InputStream is = getConfigurationSource().getInputStream();
-        Properties props = new Properties();
+        final InputStream inputStream = getConfigurationSource().getInputStream();
+        final Properties properties = new Properties();
         try {
-            props.load(is);
-        } catch (Exception e) {
+            properties.load(inputStream);
+        } catch (final Exception e) {
             LOGGER.error("Could not read configuration file [{}].", getConfigurationSource().toString(), e);
             return;
         }
         // If we reach here, then the config file is alright.
-        doConfigure(props);
+        doConfigure(properties);
     }
 
     @Override
@@ -116,8 +116,7 @@ public class PropertiesConfiguration extends Log4j1Configuration {
                 return null;
             }
             final PropertiesConfigurationFactory factory = new PropertiesConfigurationFactory();
-            final PropertiesConfiguration config =
-                    (PropertiesConfiguration) factory.getConfiguration(getLoggerContext(), source);
+            final PropertiesConfiguration config = (PropertiesConfiguration) factory.getConfiguration(getLoggerContext(), source);
             return config == null || config.getState() != State.INITIALIZING ? null : config;
         } catch (final IOException ex) {
             LOGGER.error("Cannot locate file {}: {}", getConfigurationSource(), ex);
@@ -298,7 +297,7 @@ public class PropertiesConfiguration extends Log4j1Configuration {
      *
      * <p>
      */
-    private void doConfigure(Properties properties) {
+    private void doConfigure(final Properties properties) {
         String status = "error";
         String value = properties.getProperty(DEBUG_KEY);
         if (value == null) {
@@ -325,7 +324,7 @@ public class PropertiesConfiguration extends Log4j1Configuration {
     // Internal stuff
     // --------------------------------------------------------------------------
 
-    private void configureRoot(Properties props) {
+    private void configureRoot(final Properties props) {
         String effectiveFrefix = ROOT_LOGGER_PREFIX;
         String value = OptionConverter.findAndSubst(ROOT_LOGGER_PREFIX, props);
 
@@ -337,7 +336,7 @@ public class PropertiesConfiguration extends Log4j1Configuration {
         if (value == null) {
             LOGGER.debug("Could not find root logger information. Is this OK?");
         } else {
-            LoggerConfig root = getRootLogger();
+            final LoggerConfig root = getRootLogger();
             parseLogger(props, root, effectiveFrefix, INTERNAL_ROOT_NAME, value);
         }
     }
@@ -345,10 +344,10 @@ public class PropertiesConfiguration extends Log4j1Configuration {
     /**
      * Parses non-root elements, such non-root categories and renderers.
      */
-    private void parseLoggers(Properties props) {
-        Enumeration<?> enumeration = props.propertyNames();
+    private void parseLoggers(final Properties props) {
+        final Enumeration<?> enumeration = props.propertyNames();
         while (enumeration.hasMoreElements()) {
-            String key = Objects.toString(enumeration.nextElement(), null);
+            final String key = Objects.toString(enumeration.nextElement(), null);
             if (key.startsWith(CATEGORY_PREFIX) || key.startsWith(LOGGER_PREFIX)) {
                 String loggerName = null;
                 if (key.startsWith(CATEGORY_PREFIX)) {
@@ -356,10 +355,10 @@ public class PropertiesConfiguration extends Log4j1Configuration {
                 } else if (key.startsWith(LOGGER_PREFIX)) {
                     loggerName = key.substring(LOGGER_PREFIX.length());
                 }
-                String value = OptionConverter.findAndSubst(key, props);
+                final String value = OptionConverter.findAndSubst(key, props);
                 LoggerConfig loggerConfig = getLogger(loggerName);
                 if (loggerConfig == null) {
-                    boolean additivity = getAdditivityForLogger(props, loggerName);
+                    final boolean additivity = getAdditivityForLogger(props, loggerName);
                     loggerConfig = new LoggerConfig(loggerName, org.apache.logging.log4j.Level.ERROR, additivity);
                     addLogger(loggerName, loggerConfig);
                 }
@@ -371,10 +370,10 @@ public class PropertiesConfiguration extends Log4j1Configuration {
     /**
      * Parses the additivity option for a non-root category.
      */
-    private boolean getAdditivityForLogger(Properties props, String loggerName) {
+    private boolean getAdditivityForLogger(final Properties props, final String loggerName) {
         boolean additivity = true;
-        String key = ADDITIVITY_PREFIX + loggerName;
-        String value = OptionConverter.findAndSubst(key, props);
+        final String key = ADDITIVITY_PREFIX + loggerName;
+        final String value = OptionConverter.findAndSubst(key, props);
         LOGGER.debug("Handling {}=[{}]", key, value);
         // touch additivity only if necessary
         if ((value != null) && (!value.equals(""))) {
@@ -386,11 +385,11 @@ public class PropertiesConfiguration extends Log4j1Configuration {
     /**
      * This method must work for the root category as well.
      */
-    private void parseLogger(Properties props, LoggerConfig logger, String optionKey, String loggerName, String value) {
+    private void parseLogger(final Properties props, final LoggerConfig logger, final String optionKey, final String loggerName, final String value) {
 
         LOGGER.debug("Parsing for [{}] with value=[{}].", loggerName, value);
         // We must skip over ',' but not white space
-        StringTokenizer st = new StringTokenizer(value, ",");
+        final StringTokenizer st = new StringTokenizer(value, ",");
 
         // If value is not in the form ", appender.." or "", then we should set the level of the logger.
 
@@ -401,10 +400,10 @@ public class PropertiesConfiguration extends Log4j1Configuration {
                 return;
             }
 
-            String levelStr = st.nextToken();
+            final String levelStr = st.nextToken();
             LOGGER.debug("Level token is [{}].", levelStr);
 
-            org.apache.logging.log4j.Level level = levelStr == null ? org.apache.logging.log4j.Level.ERROR :
+            final org.apache.logging.log4j.Level level = levelStr == null ? org.apache.logging.log4j.Level.ERROR :
                     OptionConverter.convertLevel(levelStr, org.apache.logging.log4j.Level.DEBUG);
             logger.setLevel(level);
             LOGGER.debug("Logger {} level set to {}", loggerName, level);
@@ -429,7 +428,7 @@ public class PropertiesConfiguration extends Log4j1Configuration {
         }
     }
 
-    public Appender parseAppender(Properties props, String appenderName) {
+    public Appender parseAppender(final Properties props, final String appenderName) {
         Appender appender = registry.get(appenderName);
         if ((appender != null)) {
             LOGGER.debug("Appender \"" + appenderName + "\" was already parsed.");
@@ -439,7 +438,7 @@ public class PropertiesConfiguration extends Log4j1Configuration {
         final String prefix = APPENDER_PREFIX + appenderName;
         final String layoutPrefix = prefix + ".layout";
         final String filterPrefix = APPENDER_PREFIX + appenderName + ".filter.";
-        String className = OptionConverter.findAndSubst(prefix, props);
+        final String className = OptionConverter.findAndSubst(prefix, props);
         appender = manager.parseAppender(appenderName, className, prefix, layoutPrefix, filterPrefix, props, this);
         if (appender == null) {
             appender = buildAppender(appenderName, className, prefix, layoutPrefix, filterPrefix, props);
@@ -456,22 +455,22 @@ public class PropertiesConfiguration extends Log4j1Configuration {
 
     private Appender buildAppender(final String appenderName, final String className, final String prefix,
             final String layoutPrefix, final String filterPrefix, final Properties props) {
-        Appender appender = newInstanceOf(className, "Appender");
+        final Appender appender = newInstanceOf(className, "Appender");
         if (appender == null) {
             return null;
         }
         appender.setName(appenderName);
         appender.setLayout(parseLayout(layoutPrefix, appenderName, props));
         final String errorHandlerPrefix = prefix + ".errorhandler";
-        String errorHandlerClass = OptionConverter.findAndSubst(errorHandlerPrefix, props);
+        final String errorHandlerClass = OptionConverter.findAndSubst(errorHandlerPrefix, props);
         if (errorHandlerClass != null) {
-            ErrorHandler eh = parseErrorHandler(props, errorHandlerPrefix, errorHandlerClass, appender);
+            final ErrorHandler eh = parseErrorHandler(props, errorHandlerPrefix, errorHandlerClass, appender);
             if (eh != null) {
                 appender.setErrorHandler(eh);
             }
         }
         appender.addFilter(parseAppenderFilters(props, filterPrefix, appenderName));
-        String[] keys = new String[] { layoutPrefix };
+        final String[] keys = new String[] { layoutPrefix };
         addProperties(appender, keys, props, prefix);
         if (appender instanceof AppenderWrapper) {
             addAppender(((AppenderWrapper) appender).getAppender());
@@ -482,8 +481,8 @@ public class PropertiesConfiguration extends Log4j1Configuration {
         return appender;
     }
 
-    public Layout parseLayout(String layoutPrefix, String appenderName, Properties props) {
-        String layoutClass = OptionConverter.findAndSubst(layoutPrefix, props);
+    public Layout parseLayout(final String layoutPrefix, final String appenderName, final Properties props) {
+        final String layoutClass = OptionConverter.findAndSubst(layoutPrefix, props);
         if (layoutClass == null) {
             return null;
         }
@@ -494,8 +493,8 @@ public class PropertiesConfiguration extends Log4j1Configuration {
         return layout;
     }
 
-    private Layout buildLayout(String layoutPrefix, String className, String appenderName, Properties props) {
-        Layout layout = newInstanceOf(className, "Layout");
+    private Layout buildLayout(final String layoutPrefix, final String className, final String appenderName, final Properties props) {
+        final Layout layout = newInstanceOf(className, "Layout");
         if (layout == null) {
             return null;
         }
@@ -507,7 +506,7 @@ public class PropertiesConfiguration extends Log4j1Configuration {
 
     public ErrorHandler parseErrorHandler(final Properties props, final String errorHandlerPrefix,
             final String errorHandlerClass, final Appender appender) {
-        ErrorHandler eh = newInstanceOf(errorHandlerClass, "ErrorHandler");
+        final ErrorHandler eh = newInstanceOf(errorHandlerClass, "ErrorHandler");
         final String[] keys = new String[] {
                 errorHandlerPrefix + "." + ROOT_REF,
                 errorHandlerPrefix + "." + LOGGER_REF,
@@ -521,7 +520,7 @@ public class PropertiesConfiguration extends Log4j1Configuration {
         final Properties edited = new Properties();
         props.stringPropertyNames().stream().filter(name -> {
             if (name.startsWith(prefix)) {
-                for (String key : keys) {
+                for (final String key : keys) {
                     if (name.equals(key)) {
                         return false;
                     }
@@ -534,26 +533,26 @@ public class PropertiesConfiguration extends Log4j1Configuration {
     }
 
 
-    public Filter parseAppenderFilters(Properties props, String filterPrefix, String appenderName) {
+    public Filter parseAppenderFilters(final Properties props, final String filterPrefix, final String appenderName) {
         // extract filters and filter options from props into a hashtable mapping
         // the property name defining the filter class to a list of pre-parsed
         // name-value pairs associated to that filter
-        int fIdx = filterPrefix.length();
-        SortedMap<String, List<NameValue>> filters = new TreeMap<>();
-        Enumeration<?> e = props.keys();
+        final int fIdx = filterPrefix.length();
+        final SortedMap<String, List<NameValue>> filters = new TreeMap<>();
+        final Enumeration<?> e = props.keys();
         String name = "";
         while (e.hasMoreElements()) {
-            String key = (String) e.nextElement();
+            final String key = (String) e.nextElement();
             if (key.startsWith(filterPrefix)) {
-                int dotIdx = key.indexOf('.', fIdx);
+                final int dotIdx = key.indexOf('.', fIdx);
                 String filterKey = key;
                 if (dotIdx != -1) {
                     filterKey = key.substring(0, dotIdx);
                     name = key.substring(dotIdx + 1);
                 }
-                List<NameValue> filterOpts = filters.computeIfAbsent(filterKey, k -> new ArrayList<>());
+                final List<NameValue> filterOpts = filters.computeIfAbsent(filterKey, k -> new ArrayList<>());
                 if (dotIdx != -1) {
-                    String value = OptionConverter.findAndSubst(key, props);
+                    final String value = OptionConverter.findAndSubst(key, props);
                     filterOpts.add(new NameValue(name, value));
                 }
             }
@@ -561,8 +560,8 @@ public class PropertiesConfiguration extends Log4j1Configuration {
 
         Filter head = null;
         Filter next = null;
-        for (Map.Entry<String, List<NameValue>> entry : filters.entrySet()) {
-            String clazz = props.getProperty(entry.getKey());
+        for (final Map.Entry<String, List<NameValue>> entry : filters.entrySet()) {
+            final String clazz = props.getProperty(entry.getKey());
             Filter filter = null;
             if (clazz != null) {
                 filter = manager.parseFilter(clazz, entry.getKey(), props, this);
@@ -583,11 +582,11 @@ public class PropertiesConfiguration extends Log4j1Configuration {
         return head;
     }
 
-    private Filter buildFilter(String className, String appenderName, List<NameValue> props) {
-        Filter filter = newInstanceOf(className, "Filter");
+    private Filter buildFilter(final String className, final String appenderName, final List<NameValue> props) {
+        final Filter filter = newInstanceOf(className, "Filter");
         if (filter != null) {
-            PropertySetter propSetter = new PropertySetter(filter);
-            for (NameValue property : props) {
+            final PropertySetter propSetter = new PropertySetter(filter);
+            for (final NameValue property : props) {
                 propSetter.setProperty(property.key, property.value);
             }
             propSetter.activate();
@@ -596,7 +595,7 @@ public class PropertiesConfiguration extends Log4j1Configuration {
     }
 
 
-    private static <T> T newInstanceOf(String className, String type) {
+    private static <T> T newInstanceOf(final String className, final String type) {
         try {
             return LoaderUtil.newInstanceOf(className);
         } catch (ClassNotFoundException | IllegalAccessException | NoSuchMethodException |
@@ -610,7 +609,7 @@ public class PropertiesConfiguration extends Log4j1Configuration {
     private static class NameValue {
         String key, value;
 
-        NameValue(String key, String value) {
+        NameValue(final String key, final String value) {
             this.key = key;
             this.value = value;
         }

[logging-log4j2] 03/03: Fix Javadoc.

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 d9a835df892401ce4e8359927940ba1aeb97e39a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jan 11 15:19:29 2022 -0500

    Fix Javadoc.
---
 .../java/org/apache/logging/log4j/core/util/Source.java  | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Source.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Source.java
index 717668f..db63c83 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Source.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Source.java
@@ -21,6 +21,7 @@ import org.apache.logging.log4j.core.config.ConfigurationSource;
 
 import java.io.File;
 import java.net.URI;
+import java.net.URL;
 import java.util.Objects;
 
 /**
@@ -34,6 +35,7 @@ public class Source {
 
     /**
      * Constructs a Source from a ConfigurationSource.
+     *
      * @param source The ConfigurationSource.
      */
     public Source(final ConfigurationSource source) {
@@ -57,7 +59,7 @@ public class Source {
     /**
      * Constructs a new {@code Source} from the specified URI.
      *
-     * @param uri the URL where the input stream originated
+     * @param uri the URI where the input stream originated
      */
     public Source(final URI uri, final long lastModified) {
         this.uri = Objects.requireNonNull(uri, "URI is null");
@@ -76,20 +78,20 @@ public class Source {
     }
 
     /**
-     * Gets the configuration source URL, or {@code null} if this configuration source is based on a file or has
-     * neither a file nor an URL.
+     * Gets the configuration source URI, or {@code null} if this configuration source is based on a file or has
+     * neither a file nor an URI.
      *
-     * @return the configuration source URL, or {@code null}
+     * @return the configuration source URI, or {@code null}
      */
     public URI getURI() {
         return uri;
     }
 
     /**
-     * Gets a string describing the configuration source file or URL, or {@code null} if this configuration source
-     * has neither a file nor an URL.
+     * Gets a string describing the configuration source file or URI, or {@code null} if this configuration source
+     * has neither a file nor an URI.
      *
-     * @return a string describing the configuration source file or URL, or {@code null}
+     * @return a string describing the configuration source file or URI, or {@code null}
      */
     public String getLocation() {
         return location;