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:10 UTC

[18/23] logging-log4j2 git commit: LOG4J2-1344 added method ByteBufferDestination.size() - count total bytes written to destination

LOG4J2-1344 added method ByteBufferDestination.size() - count total bytes written to destination

The size() method is necessary to support file rollover (file size trigger):
Managers for Rolling...Appenders currently override the write() method and count the number of written bytes there.
When the Layout encodes the LogEvent directly into the ByteBufferDestination, the write() method is not called.
The ByteBufferDestination.size() gives the Manager enough information to decide if a rollover is required.


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

Branch: refs/heads/LOG4J2-1343-no-gc-outputstreamappenders
Commit: 664755e25d2e3dd65cd1b5e783d828c622b3d1d7
Parents: 14e34fa
Author: rpopma <rp...@apache.org>
Authored: Tue Apr 5 23:19:04 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Tue Apr 5 23:19:04 2016 +0900

----------------------------------------------------------------------
 .../logging/log4j/core/appender/RandomAccessFileManager.java  | 7 +++++++
 1 file changed, 7 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/664755e2/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
index 6556ebe..63ea239 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
@@ -44,6 +44,7 @@ public class RandomAccessFileManager extends OutputStreamManager implements Byte
     private final RandomAccessFile randomAccessFile;
     private final ByteBuffer buffer;
     private final ThreadLocal<Boolean> isEndOfBatch = new ThreadLocal<>();
+    private long drained;
 
     protected RandomAccessFileManager(final RandomAccessFile file,
             final String fileName, final OutputStream os,
@@ -114,6 +115,7 @@ public class RandomAccessFileManager extends OutputStreamManager implements Byte
         buffer.flip();
         try {
             randomAccessFile.write(buffer.array(), 0, buffer.limit());
+            drained += buffer.limit();
         } catch (final IOException ex) {
             final String msg = "Error writing to RandomAccessFile " + getName();
             throw new AppenderLoggingException(msg, ex);
@@ -175,6 +177,11 @@ public class RandomAccessFileManager extends OutputStreamManager implements Byte
         return buffer;
     }
 
+    @Override
+    public long size() {
+        return drained + buffer.position();
+    }
+
     /**
      * Factory Data.
      */