You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/04/05 17:53:09 UTC

[17/23] logging-log4j2 git commit: LOG4J2-1344 RollingFileManager should detect if the garbage-free Layout mechanism is used and use the appropriate method to detect how many bytes have been written

LOG4J2-1344 RollingFileManager should detect if the garbage-free Layout mechanism is used and use the appropriate method to detect how many bytes have been written


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/14e34fac
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/14e34fac
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/14e34fac

Branch: refs/heads/LOG4J2-1343-no-gc-outputstreamappenders
Commit: 14e34fac4c988ee89569902364e14e8c071f44e6
Parents: 414e7ca
Author: rpopma <rp...@apache.org>
Authored: Tue Apr 5 23:18:26 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Tue Apr 5 23:18:26 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/appender/rolling/RollingFileManager.java       | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/14e34fac/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
index 2b824d7..734bfaa 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingFileManager.java
@@ -92,6 +92,7 @@ public class RollingFileManager extends FileManager {
 
     @Override
     protected synchronized void write(final byte[] bytes, final int offset, final int length, final boolean immediateFlush) {
+        // NOTE: this method is not called by direct encoders (they call the Layout.encode() method)
         size += length;
         super.write(bytes, offset, length, immediateFlush);
     }
@@ -101,7 +102,11 @@ public class RollingFileManager extends FileManager {
      * @return The size of the file in bytes.
      */
     public long getFileSize() {
-        return size;
+        return size + encodedSize();
+    }
+
+    private long encodedSize() {
+        return Constants.ENABLE_DIRECT_ENCODERS ? getByteBufferDestination().size() : 0L;
     }
 
     /**