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

[12/50] logging-log4j2 git commit: LOG4J2-1343 RollingFileManager should honor the user-specified buffer size, and include the bytes that are buffered but not written yet when deciding when to roll over

LOG4J2-1343 RollingFileManager should honor the user-specified buffer size, and include the bytes that are buffered but not written yet when deciding when to roll over


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

Branch: refs/heads/LOG4J2-1356
Commit: 389b391c2c4e2567b3f671ed07fa1acd5fc481aa
Parents: 3264915
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 03:00:33 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 03:00:33 2016 +0900

----------------------------------------------------------------------
 .../core/appender/rolling/RollingFileManager.java     | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/389b391c/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 81104e8..560ec6c 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
@@ -32,6 +32,7 @@ import org.apache.logging.log4j.core.appender.FileManager;
 import org.apache.logging.log4j.core.appender.ManagerFactory;
 import org.apache.logging.log4j.core.appender.rolling.action.AbstractAction;
 import org.apache.logging.log4j.core.appender.rolling.action.Action;
+import org.apache.logging.log4j.core.util.Constants;
 import org.apache.logging.log4j.core.util.Log4jThread;
 
 /**
@@ -99,6 +100,9 @@ public class RollingFileManager extends FileManager {
      * @return The size of the file in bytes.
      */
     public long getFileSize() {
+        if (Constants.ENABLE_DIRECT_ENCODERS) {
+            return size + getByteBufferDestination().getByteBuffer().position();
+        }
         return size;
     }
 
@@ -134,7 +138,10 @@ public class RollingFileManager extends FileManager {
 
     protected void createFileAfterRollover() throws IOException  {
         final OutputStream os = new FileOutputStream(getFileName(), isAppend());
-        if (getBufferSize() > 0) { // negative buffer size means no buffering
+
+        // when the garbage-free Layout encode mechanism is used
+        // we use a ByteBuffer instead of BufferedOutputStream
+        if (!Constants.ENABLE_DIRECT_ENCODERS && isBufferedIO()) {
             setOutputStream(new BufferedOutputStream(os, getBufferSize()));
         } else {
             setOutputStream(os);
@@ -402,7 +409,10 @@ public class RollingFileManager extends FileManager {
             try {
                 os = new FileOutputStream(name, data.append);
                 int bufferSize = data.bufferSize;
-                if (data.bufferedIO) {
+
+                // when the garbage-free Layout encode mechanism is used
+                // we use a ByteBuffer instead of BufferedOutputStream
+                if (!Constants.ENABLE_DIRECT_ENCODERS && data.bufferedIO) {
                     os = new BufferedOutputStream(os, bufferSize);
                 } else {
                     bufferSize = -1; // negative buffer size signals bufferedIO was configured false