logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
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 GMT
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 @@
       <action issue="LOG4J2-401" dev="ggregory" type="add">
         Configure FileAppender buffer size.
       </action>
+      <action issue="LOG4J2-402" dev="ggregory" type="add">
+        Configure RandomAccessFileAppender buffer size.
+      </action>
     </release>
     <release version="2.0-beta9" date="2013-09-14" description="Bug fixes and enhancements">
       <action issue="LOG4J2-317" dev="ggregory" type="update">

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 @@
                           </p>
 		                </td>
 					</tr>
+                    <tr>
+                      <td>bufferSize</td>
+                      <td>int</td>
+                      <td>The buffer size, defaults to 262,144 bytes (256 * 1024).</td>
+                    </tr>
 					<tr>
 						<td>layout</td>
 						<td>Layout</td>
@@ -694,7 +699,7 @@
             <tr>
               <td>bufferSize</td>
               <td>int</td>
-              <td>When bufferedIO is true, this is the buffer size, the default is
8192.</td>
+              <td>When bufferedIO is true, this is the buffer size, the default is
8192 bytes.</td>
             </tr>
             <tr>
               <td>filter</td>



Mime
View raw message