Return-Path:
X-Original-To: apmail-logging-commits-archive@minotaur.apache.org
Delivered-To: apmail-logging-commits-archive@minotaur.apache.org
Received: from mail.apache.org (hermes.apache.org [140.211.11.3])
by minotaur.apache.org (Postfix) with SMTP id 42CDB10FD9
for ;
Mon, 16 Sep 2013 21:34:00 +0000 (UTC)
Received: (qmail 70572 invoked by uid 500); 16 Sep 2013 21:33:58 -0000
Delivered-To: apmail-logging-commits-archive@logging.apache.org
Received: (qmail 70541 invoked by uid 500); 16 Sep 2013 21:33:56 -0000
Mailing-List: contact commits-help@logging.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: dev@logging.apache.org
Delivered-To: mailing list commits@logging.apache.org
Received: (qmail 70522 invoked by uid 99); 16 Sep 2013 21:33:55 -0000
Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136)
by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Sep 2013 21:33:55 +0000
X-ASF-Spam-Status: No, hits=-2000.0 required=5.0
tests=ALL_TRUSTED
X-Spam-Check-By: apache.org
Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4)
by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Sep 2013 21:33:53 +0000
Received: from eris.apache.org (localhost [127.0.0.1])
by eris.apache.org (Postfix) with ESMTP id 6726C23888D7;
Mon, 16 Sep 2013 21:33:33 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r1523822 - in /logging/log4j/log4j2/trunk:
log4j-core/src/main/java/org/apache/logging/log4j/core/appender/
log4j-core/src/test/java/org/apache/logging/log4j/core/appender/
src/changes/ src/site/xdoc/manual/
Date: Mon, 16 Sep 2013 21:33:33 -0000
To: commits@logging.apache.org
From: ggregory@apache.org
X-Mailer: svnmailer-1.0.9
Message-Id: <20130916213333.6726C23888D7@eris.apache.org>
X-Virus-Checked: Checked by ClamAV on apache.org
Author: ggregory
Date: Mon Sep 16 21:33:32 2013
New Revision: 1523822
URL: http://svn.apache.org/r1523822
Log:
[LOG4J2-402] Configure RandomAccessFileAppender buffer size.
Modified:
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java
logging/log4j/log4j2/trunk/src/changes/changes.xml
logging/log4j/log4j2/trunk/src/site/xdoc/manual/appenders.xml
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java?rev=1523822&r1=1523821&r2=1523822&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java Mon Sep 16 21:33:32 2013
@@ -30,6 +30,7 @@ import org.apache.logging.log4j.core.con
import org.apache.logging.log4j.core.config.plugins.PluginElement;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;
import org.apache.logging.log4j.core.helpers.Booleans;
+import org.apache.logging.log4j.core.helpers.Integers;
import org.apache.logging.log4j.core.layout.PatternLayout;
import org.apache.logging.log4j.core.net.Advertiser;
@@ -105,6 +106,7 @@ public final class RandomAccessFileAppen
* @param name The name of the Appender.
* @param immediateFlush "true" if the contents should be flushed on every
* write, "false" otherwise. The default is "true".
+ * @param bufferSizeStr The buffer size, defaults to {@value RandomAccessFileManager#DEFAULT_BUFFER_SIZE}.
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @param layout The layout to use to format the event. If no layout is
@@ -123,6 +125,7 @@ public final class RandomAccessFileAppen
@PluginAttribute("append") final String append,
@PluginAttribute("name") final String name,
@PluginAttribute("immediateFlush") final String immediateFlush,
+ @PluginAttribute("bufferSize") final String bufferSizeStr,
@PluginAttribute("ignoreExceptions") final String ignore,
@PluginElement("Layout") Layout extends Serializable> layout,
@PluginElement("Filters") final Filter filter,
@@ -134,6 +137,7 @@ public final class RandomAccessFileAppen
final boolean isFlush = Booleans.parseBoolean(immediateFlush, true);
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
final boolean isAdvertise = Boolean.parseBoolean(advertise);
+ final int bufferSize = Integers.parseInt(bufferSizeStr, RandomAccessFileManager.DEFAULT_BUFFER_SIZE);
if (name == null) {
LOGGER.error("No name provided for FileAppender");
@@ -149,7 +153,7 @@ public final class RandomAccessFileAppen
layout = PatternLayout.createLayout(null, null, null, null, null);
}
final RandomAccessFileManager manager = RandomAccessFileManager.getFileManager(
- fileName, isAppend, isFlush, advertiseURI, layout
+ fileName, isAppend, isFlush, bufferSize, advertiseURI, layout
);
if (manager == null) {
return null;
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java?rev=1523822&r1=1523821&r2=1523822&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java Mon Sep 16 21:33:32 2013
@@ -45,16 +45,16 @@ public class RandomAccessFileManager ext
protected RandomAccessFileManager(final RandomAccessFile file,
final String fileName, final OutputStream os,
- final boolean immediateFlush, final String advertiseURI,
- final Layout extends Serializable> layout) {
+ final boolean immediateFlush, int bufferSize,
+ final String advertiseURI, final Layout extends Serializable> layout) {
super(os, fileName, layout);
this.isImmediateFlush = immediateFlush;
this.randomAccessFile = file;
this.advertiseURI = advertiseURI;
- isEndOfBatch.set(Boolean.FALSE);
+ this.isEndOfBatch.set(Boolean.FALSE);
// TODO make buffer size configurable?
- buffer = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
+ this.buffer = ByteBuffer.allocate(bufferSize);
}
/**
@@ -65,15 +65,16 @@ public class RandomAccessFileManager ext
* be overwritten.
* @param isFlush true if the contents should be flushed to disk on every
* write
+ * @param bufferSize The buffer size.
* @param advertiseURI the URI to use when advertising the file
* @param layout The layout.
* @return A RandomAccessFileManager for the File.
*/
- public static RandomAccessFileManager getFileManager(final String fileName,
- final boolean append, final boolean isFlush,
- final String advertiseURI, final Layout extends Serializable> layout) {
+ public static RandomAccessFileManager getFileManager(final String fileName, final boolean append,
+ final boolean isFlush, int bufferSize, final String advertiseURI,
+ final Layout extends Serializable> layout) {
return (RandomAccessFileManager) getManager(fileName, new FactoryData(append,
- isFlush, advertiseURI, layout), FACTORY);
+ isFlush, bufferSize, advertiseURI, layout), FACTORY);
}
public Boolean isEndOfBatch() {
@@ -168,6 +169,7 @@ public class RandomAccessFileManager ext
private static class FactoryData {
private final boolean append;
private final boolean immediateFlush;
+ private final int bufferSize;
private final String advertiseURI;
private final Layout extends Serializable> layout;
@@ -175,11 +177,13 @@ public class RandomAccessFileManager ext
* Constructor.
*
* @param append Append status.
+ * @param bufferSize TODO
*/
public FactoryData(final boolean append, final boolean immediateFlush,
- final String advertiseURI, final Layout extends Serializable> layout) {
+ int bufferSize, final String advertiseURI, final Layout extends Serializable> layout) {
this.append = append;
this.immediateFlush = immediateFlush;
+ this.bufferSize = bufferSize;
this.advertiseURI = advertiseURI;
this.layout = layout;
}
@@ -219,7 +223,7 @@ public class RandomAccessFileManager ext
raf.setLength(0);
}
return new RandomAccessFileManager(raf, name, os, data.immediateFlush,
- data.advertiseURI, data.layout);
+ data.bufferSize, data.advertiseURI, data.layout);
} catch (final Exception ex) {
LOGGER.error("RandomAccessFileManager (" + name + ") " + ex);
}
Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java?rev=1523822&r1=1523821&r2=1523822&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java Mon Sep 16 21:33:32 2013
@@ -43,7 +43,7 @@ public class RandomAccessFileManagerTest
final RandomAccessFile raf = new RandomAccessFile(file, "rw");
final OutputStream os = new RandomAccessFileManager.DummyOutputStream();
final RandomAccessFileManager manager = new RandomAccessFileManager(raf, file.getName(), os,
- false, null, null);
+ false, RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null);
final int size = RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3;
final byte[] data = new byte[size];
@@ -65,7 +65,7 @@ public class RandomAccessFileManagerTest
final RandomAccessFile raf = new RandomAccessFile(file, "rw");
final OutputStream os = new RandomAccessFileManager.DummyOutputStream();
final RandomAccessFileManager manager = new RandomAccessFileManager(raf, file.getName(), os,
- false, null, null);
+ false, RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null);
final int size = RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3 + 1;
final byte[] data = new byte[size];
@@ -77,6 +77,25 @@ public class RandomAccessFileManagerTest
}
@Test
+ public void testWrite_dataExceedingMinBufferSize() throws IOException {
+ final File file = File.createTempFile("log4j2", "test");
+ file.deleteOnExit();
+ final RandomAccessFile raf = new RandomAccessFile(file, "rw");
+ final OutputStream os = new RandomAccessFileManager.DummyOutputStream();
+ final int bufferSize = 1;
+ final RandomAccessFileManager manager = new RandomAccessFileManager(raf, file.getName(), os,
+ false, bufferSize, null, null);
+
+ final int size = bufferSize * 3 + 1;
+ final byte[] data = new byte[size];
+ manager.write(data); // no exception
+ assertEquals(bufferSize * 3, raf.length());
+
+ manager.flush();
+ assertEquals(size, raf.length()); // all data written to file now
+ }
+
+ @Test
public void testAppendDoesNotOverwriteExistingFile() throws IOException {
final boolean isAppend = true;
final File file = File.createTempFile("log4j2", "test");
@@ -97,7 +116,7 @@ public class RandomAccessFileManagerTest
assertEquals("all flushed to disk", bytes.length, file.length());
final RandomAccessFileManager manager = RandomAccessFileManager.getFileManager(
- file.getAbsolutePath(), isAppend, true, null, null);
+ file.getAbsolutePath(), isAppend, true, RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null);
manager.write(bytes, 0, bytes.length);
final int expected = bytes.length * 2;
assertEquals("appended, not overwritten", expected, file.length());
Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1523822&r1=1523821&r2=1523822&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Mon Sep 16 21:33:32 2013
@@ -24,6 +24,9 @@
Configure FileAppender buffer size.
+
+ Configure RandomAccessFileAppender buffer size.
+
Modified: logging/log4j/log4j2/trunk/src/site/xdoc/manual/appenders.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/xdoc/manual/appenders.xml?rev=1523822&r1=1523821&r2=1523822&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/site/xdoc/manual/appenders.xml (original)
+++ logging/log4j/log4j2/trunk/src/site/xdoc/manual/appenders.xml Mon Sep 16 21:33:32 2013
@@ -361,6 +361,11 @@
+
+ bufferSize |
+ int |
+ The buffer size, defaults to 262,144 bytes (256 * 1024). |
+
layout |
Layout |
@@ -694,7 +699,7 @@
bufferSize |
int |
- When bufferedIO is true, this is the buffer size, the default is 8192. |
+ When bufferedIO is true, this is the buffer size, the default is 8192 bytes. |
filter |