logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1516494 - /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
Date Thu, 22 Aug 2013 16:02:23 GMT
Author: ggregory
Date: Thu Aug 22 16:02:23 2013
New Revision: 1516494

URL: http://svn.apache.org/r1516494
Log:
Don't leak random access file handle in case of an access error. Log this access at the TRACE
level.

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java?rev=1516494&r1=1516493&r2=1516494&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
Thu Aug 22 16:02:23 2013
@@ -148,18 +148,28 @@ public class RollingRandomAccessFileMana
             final long size = data.append ? file.length() : 0;
             final long time = file.exists() ? file.lastModified() : System.currentTimeMillis();
 
-            RandomAccessFile raf;
+            RandomAccessFile raf = null;
             try {
                 raf = new RandomAccessFile(name, "rw");
                 if (data.append) {
-                    raf.seek(raf.length());
+                    final long length = raf.length();
+                    LOGGER.trace("RandomAccessFile {} seek to {}", name, length);
+                    raf.seek(length);
                 } else {
+                    LOGGER.trace("RandomAccessFile {} set length to 0", name);
                     raf.setLength(0);
                 }
                 return new RollingRandomAccessFileManager(raf, name, data.pattern, new DummyOutputStream(),
data.append,
                         data.immediateFlush, size, time, data.policy, data.strategy, data.advertiseURI,
data.layout);
             } catch (final IOException ex) {
-                LOGGER.error("RollingRandomAccessFileManager (" + name + ") " + ex);
+                LOGGER.error("Cannot access RandomAccessFile {}) " + ex);
+                if (raf != null) {
+                    try {
+                        raf.close();
+                    } catch (IOException e) {
+                        LOGGER.error("Cannot close RandomAccessFile {}", name, e);
+                    }
+                }
             }
             return null;
         }



Mime
View raw message