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:12 UTC
[20/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/209323c1
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/209323c1
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/209323c1
Branch: refs/heads/LOG4J2-1343-no-gc-outputstreamappenders
Commit: 209323c171015cfdf3a99b3e3477be11f17f7e31
Parents: 664755e
Author: rpopma <rp...@apache.org>
Authored: Tue Apr 5 23:19:46 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Tue Apr 5 23:19:46 2016 +0900
----------------------------------------------------------------------
.../appender/rolling/RollingRandomAccessFileManager.java | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/209323c1/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
index 5b3fc05..6ce0dfc 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManager.java
@@ -45,6 +45,7 @@ public class RollingRandomAccessFileManager extends RollingFileManager implement
private RandomAccessFile randomAccessFile;
private final ByteBuffer buffer;
private final ThreadLocal<Boolean> isEndOfBatch = new ThreadLocal<>();
+ private long drained;
public RollingRandomAccessFileManager(final RandomAccessFile raf, final String fileName, final String pattern,
final OutputStream os, final boolean append, final boolean immediateFlush, final int bufferSize,
@@ -100,6 +101,8 @@ public class RollingRandomAccessFileManager extends RollingFileManager implement
@Override
protected synchronized void write(final byte[] bytes, int offset, int length, final boolean immediateFlush) {
+ // NOTE: this method is not called by direct encoders (they call the Layout.encode() method)
+ size += buffer.limit(); // track file size
int chunk = 0;
do {
if (length > buffer.remaining()) {
@@ -130,7 +133,7 @@ public class RollingRandomAccessFileManager extends RollingFileManager implement
buffer.flip();
try {
randomAccessFile.write(buffer.array(), 0, buffer.limit());
- size += buffer.limit(); // track file size
+ drained += buffer.limit();
} catch (final IOException ex) {
final String msg = "Error writing to RandomAccessFile " + getName();
throw new AppenderLoggingException(msg, ex);
@@ -169,6 +172,11 @@ public class RollingRandomAccessFileManager extends RollingFileManager implement
return buffer;
}
+ @Override
+ public long size() {
+ return drained + buffer.position();
+ }
+
/**
* Factory to create a RollingRandomAccessFileManager.
*/