logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1511342 - in /logging/log4j/log4j2/trunk: api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java api/src/main/java/org/apache/logging/log4j/util/ProviderUtil.java src/changes/changes.xml
Date Wed, 07 Aug 2013 14:54:05 GMT
Author: ggregory
Date: Wed Aug  7 14:54:04 2013
New Revision: 1511342

URL: http://svn.apache.org/r1511342
Log:
[LOG4J2-320] JPAAppender stops logging because META-INF/log4j-provider.properties is left
open. Refactor loading and closing a properties stream into a new method PropertiesUtil#loadClose().

Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/ProviderUtil.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java?rev=1511342&r1=1511341&r2=1511342&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
Wed Aug  7 14:54:04 2013
@@ -18,41 +18,61 @@ package org.apache.logging.log4j.util;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URL;
 import java.util.Properties;
 
+import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.status.StatusLogger;
 
 /**
- * Helps access System Properties.
+ * Helps access properties.
  */
 public class PropertiesUtil {
 
     private static final PropertiesUtil LOG4J_PROPERTIES = new PropertiesUtil("log4j2.component.properties");
 
+    private static final Logger LOGGER = StatusLogger.getLogger();
+    
     private final Properties props;
 
     public PropertiesUtil(final Properties props) {
         this.props = props;
     }
 
-    public PropertiesUtil(final String propsLocn) {
-        this.props = new Properties();
-        final ClassLoader loader = ProviderUtil.findClassLoader();
-        final InputStream in = loader.getResourceAsStream(propsLocn);
-        if (null != in) {
-            try {
-                this.props.load(in);
-            } catch (final IOException e) {
-                // ignored
-            } finally {
-                try {
-                    in.close();
-                } catch (final IOException e) {
-                    // ignored
-                }
-            }
-        }
-    }
+	/**
+	 * Loads and closes the given property input stream.
+	 * If an error occurs, log to the status logger.
+	 * 
+	 * @param in
+	 *            a property input stream.
+	 * @param source
+	 *            a source object describing the source, like a resource string
+	 *            or a URL.
+	 * @return a new Properties object
+	 */
+	static Properties loadClose(InputStream in, Object source) {
+		Properties props = new Properties();
+		if (null != in) {
+			try {
+				props.load(in);
+			} catch (final IOException e) {
+				LOGGER.error("Unable to read " + source, e);
+			} finally {
+				try {
+					in.close();
+				} catch (final IOException e) {
+					LOGGER.error("Unable to close " + source, e);
+				}
+			}
+		}
+		return props;
+	}
+    
+	public PropertiesUtil(final String propsLocn) {
+		final ClassLoader loader = ProviderUtil.findClassLoader();
+		final InputStream in = loader.getResourceAsStream(propsLocn);
+		this.props = loadClose(in, propsLocn);
+	}
 
     public static PropertiesUtil getProperties() {
         return LOG4J_PROPERTIES;

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/ProviderUtil.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/ProviderUtil.java?rev=1511342&r1=1511341&r2=1511342&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/ProviderUtil.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/ProviderUtil.java
Wed Aug  7 14:54:04 2013
@@ -58,17 +58,17 @@ public final class ProviderUtil {
 
         if (enumResources != null) {
             while (enumResources.hasMoreElements()) {
-                final Properties props = new Properties();
                 final URL url = enumResources.nextElement();
+                Properties props;
                 try {
-                    props.load(url.openStream());
+                    props = PropertiesUtil.loadClose(url.openStream(), url);
+                    if (!validVersion(props.getProperty(API_VERSION))) {
+                        continue;
+                    }
+                    PROVIDERS.add(new Provider(props, url));
                 } catch (final IOException ioe) {
-                    LOGGER.error("Unable to read " + url.toString(), ioe);
-                }
-                if (!validVersion(props.getProperty(API_VERSION))) {
-                    continue;
+                    LOGGER.error("Unable to open " + url.toString(), ioe);
                 }
-                PROVIDERS.add(new Provider(props, url));
             }
         }
     }

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1511342&r1=1511341&r2=1511342&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Wed Aug  7 14:54:04 2013
@@ -21,6 +21,9 @@
   </properties>
   <body>
     <release version="2.0-beta9" date="soon, very soon" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-320" dev="ggregory" type="fix">
+        JPAAppender stops logging because META-INF/log4j-provider.properties is left open.
+      </action>
       <action issue="LOG4J2-335" dev="rgoers" type="fix">
         FlumePersistentManager's writer thread had high CPU usage.
       </action>



Mime
View raw message