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/06 20:11:37 UTC
[01/18] logging-log4j2 git commit: LOG4J2-1343 Added
Constants.ENABLE_DIRECT_ENCODERS kill switch for the garbage-free Layout
mechanism
Repository: logging-log4j2
Updated Branches:
refs/heads/master b60bf6f13 -> 04a10cfcb
LOG4J2-1343 Added Constants.ENABLE_DIRECT_ENCODERS kill switch for the garbage-free Layout mechanism
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a95eeb85
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a95eeb85
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a95eeb85
Branch: refs/heads/master
Commit: a95eeb85db063e2e061a3152aa41924563291d82
Parents: b60bf6f
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 02:52:34 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 02:52:34 2016 +0900
----------------------------------------------------------------------
.../org/apache/logging/log4j/core/util/Constants.java | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a95eeb85/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
index 6cd0e8a..dd1cd27 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
@@ -72,7 +72,7 @@ public final class Constants {
"log4j.format.msg.async", false);
/**
- * {@code true} if we think we are running in a web container, base on the boolean value of system property
+ * {@code true} if we think we are running in a web container, based on the boolean value of system property
* "log4j2.is.webapp", or (if this system property is not set) whether the {@code javax.servlet.Servlet} class
* is present in the classpath.
*/
@@ -91,6 +91,18 @@ public final class Constants {
"log4j2.enable.threadlocals", true);
/**
+ * Kill switch for garbage-free Layout behaviour that encodes LogEvents directly into
+ * {@link org.apache.logging.log4j.core.layout.ByteBufferDestination}s without creating intermediate temporary
+ * Objects.
+ * <p>
+ * {@code True} by default, disable by setting system property "log4j2.enable.direct.encoders" to "false".
+ *
+ * @since 2.6
+ */
+ public static final boolean ENABLE_DIRECT_ENCODERS = PropertiesUtil.getProperties().getBooleanProperty(
+ "log4j2.enable.direct.encoders", true);
+
+ /**
* Prevent class instantiation.
*/
private Constants() {
[02/18] logging-log4j2 git commit: LOG4J2-1343 Added
OutputStreamManagerDestination that adapts an OutputStreamManager to the
ByteBufferDestination interface
Posted by rp...@apache.org.
LOG4J2-1343 Added OutputStreamManagerDestination that adapts an OutputStreamManager to the ByteBufferDestination interface
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/49878b43
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/49878b43
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/49878b43
Branch: refs/heads/master
Commit: 49878b435b97f6f771a0f02e2621aabfb3b25d60
Parents: a95eeb8
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 02:53:44 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 02:53:44 2016 +0900
----------------------------------------------------------------------
.../OutputStreamManagerDestination.java | 59 ++++++++++++++++++++
1 file changed, 59 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/49878b43/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManagerDestination.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManagerDestination.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManagerDestination.java
new file mode 100644
index 0000000..18689a1
--- /dev/null
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManagerDestination.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.appender;
+
+import java.nio.ByteBuffer;
+import java.util.Objects;
+
+import org.apache.logging.log4j.core.layout.ByteBufferDestination;
+
+/**
+ * Decorates an {@code OutputStreamManager} to adapt it to the {@code ByteBufferDestination} interface.
+ */
+public class OutputStreamManagerDestination implements ByteBufferDestination {
+ private static final int DEFAULT_BUFFER_SIZE = 8 * 1024;
+ private final ByteBuffer byteBuffer;
+ private final boolean immediateFlush;
+ private final OutputStreamManager outputStreamManager;
+
+ public OutputStreamManagerDestination(final boolean immediateFlush, final OutputStreamManager outputStreamManager) {
+ this(DEFAULT_BUFFER_SIZE, immediateFlush, outputStreamManager);
+ }
+
+ public OutputStreamManagerDestination(final int bufferSize, final boolean immediateFlush,
+ final OutputStreamManager outputStreamManager) {
+
+ this.byteBuffer = ByteBuffer.wrap(new byte[bufferSize]);
+ this.immediateFlush = immediateFlush;
+ this.outputStreamManager = Objects.requireNonNull(outputStreamManager, "outputStreamManager");
+ }
+
+ @Override
+ public ByteBuffer getByteBuffer() {
+ return byteBuffer;
+ }
+
+ @Override
+ public ByteBuffer drain(final ByteBuffer buf) {
+ buf.flip();
+ if (buf.limit() > 0) {
+ outputStreamManager.write(buf.array(), 0, buf.limit(), immediateFlush);
+ }
+ buf.clear();
+ return buf;
+ }
+}
[08/18] logging-log4j2 git commit: LOG4J2-1343 simplified
RandomAccessFileAppender to reuse the garbage-free Layout mechanism defined
in the superclass
Posted by rp...@apache.org.
LOG4J2-1343 simplified RandomAccessFileAppender to reuse the garbage-free Layout mechanism defined in the superclass
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/e0fa54a6
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/e0fa54a6
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/e0fa54a6
Branch: refs/heads/master
Commit: e0fa54a67ca5991305528f77fdb19b99357f7403
Parents: 389b391
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 03:01:45 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 03:01:45 2016 +0900
----------------------------------------------------------------------
.../log4j/core/appender/RandomAccessFileAppender.java | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e0fa54a6/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java
index 8bcf8e2..043bccf 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java
@@ -85,17 +85,8 @@ public final class RandomAccessFileAppender extends AbstractOutputStreamAppender
// of immediateFlush=true.
getManager().setEndOfBatch(event.isEndOfBatch());
- // LOG4J2-1292 utilize gc-free Layout.encode() method
- // super.append(event);
- try {
- getLayout().encode(event, getManager());
- if (getImmediateFlush() || event.isEndOfBatch()) {
- getManager().flush();
- }
- } catch (final AppenderLoggingException ex) {
- error("Unable to write to stream " + getManager().getName() + " for appender " + getName());
- throw ex;
- }
+ // LOG4J2-1292 utilize gc-free Layout.encode() method: taken care of in superclass
+ super.append(event);
}
/**
[09/18] logging-log4j2 git commit: LOG4J2-1343 simplified
RollingRandomAccessFileAppender to reuse the garbage-free Layout mechanism
defined in the superclass
Posted by rp...@apache.org.
LOG4J2-1343 simplified RollingRandomAccessFileAppender to reuse the garbage-free Layout mechanism defined in the superclass
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/920f8aa2
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/920f8aa2
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/920f8aa2
Branch: refs/heads/master
Commit: 920f8aa2bccc37cd2dd2624de3a338192d942573
Parents: e0fa54a
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 03:02:18 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 03:02:18 2016 +0900
----------------------------------------------------------------------
.../core/appender/RollingRandomAccessFileAppender.java | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/920f8aa2/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java
index 21cff5b..1eea8f5 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java
@@ -95,17 +95,8 @@ public final class RollingRandomAccessFileAppender extends AbstractOutputStreamA
// of immediateFlush=true.
manager.setEndOfBatch(event.isEndOfBatch());
- // LOG4J2-1292 utilize gc-free Layout.encode() method
- // super.append(event);
- try {
- getLayout().encode(event, getManager());
- if (getImmediateFlush() || event.isEndOfBatch()) {
- getManager().flush();
- }
- } catch (final AppenderLoggingException ex) {
- error("Unable to write to stream " + getManager().getName() + " for appender " + getName());
- throw ex;
- }
+ // LOG4J2-1292 utilize gc-free Layout.encode() method: taken care of in superclass
+ super.append(event);
}
/**
[16/18] logging-log4j2 git commit: LOG4J2-1343 update test for new
garbage-free Layout mechanism,
logic for dealing with messages larger than buffer size changed
Posted by rp...@apache.org.
LOG4J2-1343 update test for new garbage-free Layout mechanism, logic for dealing with messages larger than buffer size changed
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/95c26139
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/95c26139
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/95c26139
Branch: refs/heads/master
Commit: 95c261395212c2896ac88f33d845df3cda934cc0
Parents: 8b7028a
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 03:09:30 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 03:09:30 2016 +0900
----------------------------------------------------------------------
.../core/appender/RandomAccessFileManagerTest.java | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/95c26139/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java
index 07e8ab2..b048e8a 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java
@@ -49,13 +49,14 @@ public class RandomAccessFileManagerTest {
final OutputStream os = NullOutputStream.NULL_OUTPUT_STREAM;
final RandomAccessFileManager manager = new RandomAccessFileManager(raf, file.getName(), os, false,
RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null, true);
+ manager.setByteBufferDestination(manager.createByteBufferDestination(false));
final int size = RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3;
final byte[] data = new byte[size];
manager.write(data); // no buffer overflow exception
- // buffer is full but not flushed yet
- assertEquals(RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 2, raf.length());
+ // all data is written if exceeds buffer size
+ assertEquals(RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3, raf.length());
}}
/**
@@ -70,16 +71,18 @@ public class RandomAccessFileManagerTest {
final OutputStream os = NullOutputStream.NULL_OUTPUT_STREAM;
final RandomAccessFileManager manager = new RandomAccessFileManager(raf, file.getName(), os, false,
RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null, true);
+ manager.setByteBufferDestination(manager.createByteBufferDestination(false));
final int size = RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3 + 1;
final byte[] data = new byte[size];
manager.write(data); // no exception
- assertEquals(RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3, raf.length());
+ // all data is written if exceeds buffer size
+ assertEquals(RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3 + 1, raf.length());
manager.flush();
assertEquals(size, raf.length()); // all data written to file now
}}
-
+
@Test
public void testConfigurableBufferSize() throws IOException {
final File file = folder.newFile();
@@ -103,11 +106,13 @@ public class RandomAccessFileManagerTest {
final int bufferSize = 1;
final RandomAccessFileManager manager = new RandomAccessFileManager(raf, file.getName(), os, false,
bufferSize, null, null, true);
+ manager.setByteBufferDestination(manager.createByteBufferDestination(false));
final int size = bufferSize * 3 + 1;
final byte[] data = new byte[size];
manager.write(data); // no exception
- assertEquals(bufferSize * 3, raf.length());
+ // all data is written if exceeds buffer size
+ assertEquals(bufferSize * 3 + 1, raf.length());
manager.flush();
assertEquals(size, raf.length()); // all data written to file now
[13/18] logging-log4j2 git commit: LOG4J2-1343 enabled
MemoryMappedFileManager to reuse the garbage-free Layout mechanism defined in
the superclass
Posted by rp...@apache.org.
LOG4J2-1343 enabled MemoryMappedFileManager to reuse the garbage-free Layout mechanism defined in the superclass
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/ef0023a4
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/ef0023a4
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/ef0023a4
Branch: refs/heads/master
Commit: ef0023a4087df35bc89ffc3f84a668995f2ca352
Parents: 875cec8
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 03:07:31 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 03:07:31 2016 +0900
----------------------------------------------------------------------
.../core/appender/MemoryMappedFileManager.java | 57 +++++++++++++++++---
1 file changed, 50 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ef0023a4/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
index 9335ddb..dc9fc88 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java
@@ -22,6 +22,7 @@ import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.io.Serializable;
import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
@@ -33,6 +34,7 @@ import java.util.Map;
import java.util.Objects;
import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.layout.ByteBufferDestination;
import org.apache.logging.log4j.core.util.Closer;
import org.apache.logging.log4j.core.util.NullOutputStream;
@@ -42,7 +44,7 @@ import org.apache.logging.log4j.core.util.NullOutputStream;
* Extends OutputStreamManager but instead of using a buffered output stream, this class maps a region of a file into
* memory and writes to this memory region.
* <p>
- *
+ *
* @see <a href="http://www.codeproject.com/Tips/683614/Things-to-Know-about-Memory-Mapped-File-in-Java">
* http://www.codeproject.com/Tips/683614/Things-to-Know-about-Memory-Mapped-File-in-Java</a>
* @see <a href="http://bugs.java.com/view_bug.do?bug_id=6893654">http://bugs.java.com/view_bug.do?bug_id=6893654</a>
@@ -50,11 +52,11 @@ import org.apache.logging.log4j.core.util.NullOutputStream;
* @see <a
* href="http://stackoverflow.com/questions/9261316/memory-mapped-mappedbytebuffer-or-direct-bytebuffer-for-db-implementation">
* http://stackoverflow.com/questions/9261316/memory-mapped-mappedbytebuffer-or-direct-bytebuffer-for-db-implementation</a>
- *
+ *
* @since 2.1
*/
//CHECKSTYLE:ON
-public class MemoryMappedFileManager extends OutputStreamManager {
+public class MemoryMappedFileManager extends OutputStreamManager implements ByteBufferDestination {
/**
* Default length of region to map.
*/
@@ -111,6 +113,21 @@ public class MemoryMappedFileManager extends OutputStreamManager {
}
@Override
+ protected void write(final byte[] bytes) {
+ write(bytes, 0, bytes.length, false);
+ }
+
+ @Override
+ protected void write(final byte[] bytes, final boolean immediateFlush) {
+ write(bytes, 0, bytes.length, immediateFlush);
+ }
+
+ @Override
+ protected void write(final byte[] bytes, final int offset, final int length) {
+ write(bytes, 0, bytes.length, false);
+ }
+
+ @Override
protected synchronized void write(final byte[] bytes, int offset, int length, final boolean immediateFlush) {
super.write(bytes, offset, length, immediateFlush); // writes to dummy output stream
@@ -141,7 +158,7 @@ public class MemoryMappedFileManager extends OutputStreamManager {
final float millis = (float) ((System.nanoTime() - startNanos) / NANOS_PER_MILLISEC);
LOGGER.debug("{} {} extended {} OK in {} millis", getClass().getSimpleName(), getName(), getFileName(),
millis);
-
+
mappedBuffer = mmap(randomAccessFile.getChannel(), getFileName(), offset, length);
mappingOffset = offset;
} catch (final Exception ex) {
@@ -235,7 +252,7 @@ public class MemoryMappedFileManager extends OutputStreamManager {
/**
* Returns the length of the memory mapped region.
- *
+ *
* @return the length of the mapped region
*/
public int getRegionLength() {
@@ -245,7 +262,7 @@ public class MemoryMappedFileManager extends OutputStreamManager {
/**
* Returns {@code true} if the content of the buffer should be forced to the storage device on every write,
* {@code false} otherwise.
- *
+ *
* @return whether each write should be force-sync'ed
*/
public boolean isImmediateFlush() {
@@ -257,7 +274,7 @@ public class MemoryMappedFileManager extends OutputStreamManager {
* <p>
* Key: "fileURI" Value: provided "advertiseURI" param.
* </p>
- *
+ *
* @return Map of content format keys supporting FileManager
*/
@Override
@@ -268,6 +285,32 @@ public class MemoryMappedFileManager extends OutputStreamManager {
}
/**
+ * Returns this {@code MemoryMappedFileManager}.
+ * @param immediateFlush ignored
+ * @return this {@code MemoryMappedFileManager}
+ */
+ @Override
+ protected ByteBufferDestination createByteBufferDestination(final boolean immediateFlush) {
+ return this;
+ }
+
+ @Override
+ protected void flushBuffer() {
+ // do nothing (avoid spurious calls to remap())
+ }
+
+ @Override
+ public ByteBuffer getByteBuffer() {
+ return mappedBuffer;
+ }
+
+ @Override
+ public ByteBuffer drain(final ByteBuffer buf) {
+ remap();
+ return mappedBuffer;
+ }
+
+ /**
* Factory Data.
*/
private static class FactoryData {
[07/18] 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
Posted by rp...@apache.org.
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/master
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
[10/18] logging-log4j2 git commit: LOG4J2-1343 refactored
RandomAccessFileManager to reuse the garbage-free Layout mechanism defined in
the superclass, simplified logic when bytes to write exceed buffer size
Posted by rp...@apache.org.
LOG4J2-1343 refactored RandomAccessFileManager to reuse the garbage-free Layout mechanism defined in the superclass, simplified logic when bytes to write exceed buffer size
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/32e557bf
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/32e557bf
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/32e557bf
Branch: refs/heads/master
Commit: 32e557bfffc9330242f7acacfc7a12c4553695ba
Parents: 920f8aa
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 03:04:27 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 03:04:27 2016 +0900
----------------------------------------------------------------------
.../core/appender/RandomAccessFileManager.java | 44 +++++++++++++-------
1 file changed, 30 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/32e557bf/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 ec616c4..9b7fc91 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
@@ -89,31 +89,37 @@ public class RandomAccessFileManager extends OutputStreamManager implements Byte
protected synchronized void write(final byte[] bytes, int offset, int length, final boolean immediateFlush) {
super.write(bytes, offset, length, immediateFlush); // writes to dummy output stream
- int chunk = 0;
- do {
- if (length > buffer.remaining()) {
- flush();
- }
- chunk = Math.min(length, buffer.remaining());
- buffer.put(bytes, offset, chunk);
- offset += chunk;
- length -= chunk;
- } while (length > 0);
+ if (length >= buffer.capacity()) {
+ // if request length exceeds buffer capacity, flush the buffer and write the data directly
+ flush();
+ writeToRandomAccessFile(bytes, offset, length);
+ return;
+ }
+ if (length > buffer.remaining()) {
+ flush();
+ }
+ buffer.put(bytes, offset, length);
if (immediateFlush || isImmediateFlush || isEndOfBatch.get() == Boolean.TRUE) {
flush();
}
}
- @Override
- public synchronized void flush() {
- buffer.flip();
+ private void writeToRandomAccessFile(final byte[] bytes, final int offset, final int length) {
try {
- randomAccessFile.write(buffer.array(), 0, buffer.limit());
+ randomAccessFile.write(bytes, offset, length);
} catch (final IOException ex) {
final String msg = "Error writing to RandomAccessFile " + getName();
throw new AppenderLoggingException(msg, ex);
}
+ }
+
+ @Override
+ public synchronized void flush() {
+ buffer.flip();
+ if (buffer.limit() > 0) {
+ writeToRandomAccessFile(buffer.array(), 0, buffer.limit());
+ }
buffer.clear();
}
@@ -160,6 +166,16 @@ public class RandomAccessFileManager extends OutputStreamManager implements Byte
return result;
}
+ /**
+ * Returns this {@code RandomAccessFileManager}.
+ * @param immediateFlush ignored
+ * @return this {@code RandomAccessFileManager}
+ */
+ @Override
+ protected ByteBufferDestination createByteBufferDestination(final boolean immediateFlush) {
+ return this;
+ }
+
@Override
public ByteBuffer getByteBuffer() {
return buffer;
[17/18] logging-log4j2 git commit: LOG4J2-1343 update test for new
garbage-free Layout mechanism,
logic for dealing with messages larger than buffer size changed
Posted by rp...@apache.org.
LOG4J2-1343 update test for new garbage-free Layout mechanism, logic for dealing with messages larger than buffer size changed
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/306bfcad
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/306bfcad
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/306bfcad
Branch: refs/heads/master
Commit: 306bfcadfa90f1c1580a6e7a59d688db597006a8
Parents: 95c2613
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 03:09:45 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 03:09:45 2016 +0900
----------------------------------------------------------------------
.../appender/rolling/RollingRandomAccessFileManagerTest.java | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/306bfcad/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java
index 4baddac..7b6403f 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingRandomAccessFileManagerTest.java
@@ -69,8 +69,7 @@ public class RollingRandomAccessFileManagerTest {
manager.write(data, 0, data.length, flushNow); // no buffer overflow exception
// buffer is full but not flushed yet
- assertEquals(RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE * 2,
- raf.length());
+ assertEquals(RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3, raf.length());
}
/**
@@ -98,8 +97,7 @@ public class RollingRandomAccessFileManagerTest {
final int size = RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3 + 1;
final byte[] data = new byte[size];
manager.write(data, 0, data.length, flushNow); // no exception
- assertEquals(RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3,
- raf.length());
+ assertEquals(RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3 + 1, raf.length());
manager.flush();
assertEquals(size, raf.length()); // all data written to file now
[18/18] logging-log4j2 git commit: LOG4J2-1295 increased scope of
garbage-free logging test to include Console, File, RollingFile,
RollingRandomAccessFile,
MemoryMappedFile (and the previous RandomAccessFile) appenders
Posted by rp...@apache.org.
LOG4J2-1295 increased scope of garbage-free logging test to include Console, File, RollingFile, RollingRandomAccessFile, MemoryMappedFile (and the previous RandomAccessFile) appenders
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/04a10cfc
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/04a10cfc
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/04a10cfc
Branch: refs/heads/master
Commit: 04a10cfcbaee758abac02494f491795253ef39c7
Parents: 306bfca
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 03:11:29 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 03:11:29 2016 +0900
----------------------------------------------------------------------
.../logging/log4j/core/GcFreeLoggingTest.java | 5 ++-
log4j-core/src/test/resources/gcFreeLogging.xml | 45 +++++++++++++++++++-
2 files changed, 47 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/04a10cfc/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTest.java
index eed91ec..c151917 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTest.java
@@ -57,7 +57,9 @@ public class GcFreeLoggingTest {
process.exitValue();
final String output = new String(Files.readAllBytes(tempFile.toPath()));
- assertEquals("", output);
+ final String NEWLINE = System.getProperty("line.separator");
+ assertEquals("FATAL o.a.l.l.c.GcFreeLoggingTest [main] This message is logged to the console"
+ + NEWLINE, output);
}
/**
@@ -76,6 +78,7 @@ public class GcFreeLoggingTest {
// This is not steady-state logging and will allocate objects.
final Logger logger = LogManager.getLogger(GcFreeLoggingTest.class.getName());
logger.debug("debug not set");
+ logger.fatal("This message is logged to the console");
logger.error("Sample error message");
logger.error("Test parameterized message {}", "param");
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/04a10cfc/log4j-core/src/test/resources/gcFreeLogging.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/gcFreeLogging.xml b/log4j-core/src/test/resources/gcFreeLogging.xml
index 560c83c..b477bdc 100644
--- a/log4j-core/src/test/resources/gcFreeLogging.xml
+++ b/log4j-core/src/test/resources/gcFreeLogging.xml
@@ -1,11 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="OFF">
<Appenders>
- <RandomAccessFile name="RandomAccessFilePattern" fileName="gcfree.log" immediateFlush="false" append="false">
+ <Console name="Console" target="SYSTEM_OUT">
+ <PatternLayout pattern="%p %c{1.} [%t] %X{aKey} %m%ex%n" />
+ </Console>
+ <File name="File" fileName="target/gcfreefile.log" bufferedIO="false">
+ <PatternLayout>
+ <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
+ </PatternLayout>
+ </File>
+ <RollingFile name="RollingFile" fileName="target/gcfreeRollingFile.log"
+ filePattern="target/gcfree-%d{MM-dd-yy-HH-mm-ss}.log.gz">
+ <PatternLayout>
+ <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
+ </PatternLayout>
+ <Policies>
+ <SizeBasedTriggeringPolicy size="50M" />
+ </Policies>
+ </RollingFile>
+ <RandomAccessFile name="RandomAccessFile" fileName="target/gcfreeRAF.log" immediateFlush="false" append="false">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %X{aKey} %m %ex%n</Pattern>
</PatternLayout>
</RandomAccessFile>
+ <RollingRandomAccessFile name="RollingRandomAccessFile"
+ fileName="target/gcfreeRRAF.log"
+ filePattern="target/afterRollover-%i.log" append="false"
+ immediateFlush="false">
+ <PatternLayout>
+ <Pattern>%d %p %c{1.} [%t] %X{aKey} %m %location %ex%n</Pattern>
+ </PatternLayout>
+ <Policies>
+ <SizeBasedTriggeringPolicy size="50 M"/>
+ </Policies>
+ </RollingRandomAccessFile>
+ <MemoryMappedFile name="MemoryMappedFile"
+ fileName="target/gcfreemmap.log"
+ immediateFlush="false" append="false">
+ <PatternLayout>
+ <Pattern>%d %p %c{1.} [%t] %X{aKey} %m%ex%n</Pattern>
+ </PatternLayout>
+ </MemoryMappedFile>
<!--
<RandomAccessFile name="RandomAccessFileGelf" fileName="gcfree.json" immediateFlush="false" append="false">
<GelfLayout compressionType="OFF"/>
@@ -14,7 +49,13 @@
</Appenders>
<Loggers>
<Root level="info" includeLocation="false">
- <appender-ref ref="RandomAccessFilePattern"/>
+ <appender-ref ref="Console" level="FATAL" />
+ <appender-ref ref="File"/>
+ <appender-ref ref="RandomAccessFile"/>
+ <appender-ref ref="RollingRandomAccessFile"/>
+ <appender-ref ref="File"/>
+ <appender-ref ref="RollingFile"/>
+ <appender-ref ref="MemoryMappedFile"/>
<!-- <appender-ref ref="RandomAccessFileGelf"/> -->
</Root>
</Loggers>
[14/18] logging-log4j2 git commit: LOG4J2-1343 minor test update
Posted by rp...@apache.org.
LOG4J2-1343 minor test update
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/4dc2163a
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/4dc2163a
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/4dc2163a
Branch: refs/heads/master
Commit: 4dc2163ab67ec2105869dcd9cf39d06c6cc7b35e
Parents: ef0023a
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 03:08:03 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 03:08:03 2016 +0900
----------------------------------------------------------------------
.../MemoryMappedFileAppenderLocationTest.java | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4dc2163a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/MemoryMappedFileAppenderLocationTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/MemoryMappedFileAppenderLocationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/MemoryMappedFileAppenderLocationTest.java
index 113abab..8f2c4b7 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/MemoryMappedFileAppenderLocationTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/MemoryMappedFileAppenderLocationTest.java
@@ -36,7 +36,7 @@ import static org.junit.Assert.*;
* Tests that logged strings and their location appear in the file,
* that the file size is the next power of two of the specified mapped region length
* and that the file is shrunk to its actual usage when done.
- *
+ *
* @since 2.1
*/
public class MemoryMappedFileAppenderLocationTest {
@@ -45,7 +45,7 @@ public class MemoryMappedFileAppenderLocationTest {
@Before
public void before() {
- System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
+ System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
"MemoryMappedFileAppenderLocationTest.xml");
}
@@ -53,19 +53,19 @@ public class MemoryMappedFileAppenderLocationTest {
public void testMemMapLocation() throws Exception {
final File f = new File(LOGFILE);
if (f.exists()) {
- assertTrue(f.delete());
+ assertTrue("deleted ok", f.delete());
}
assertTrue(!f.exists());
-
+
final int expectedFileLength = Integers.ceilingNextPowerOfTwo(32000);
assertEquals(32768, expectedFileLength);
-
+
final Logger log = LogManager.getLogger();
try {
log.warn("Test log1");
assertTrue(f.exists());
assertEquals("initial length", expectedFileLength, f.length());
-
+
log.warn("Test log2");
assertEquals("not grown", expectedFileLength, f.length());
} finally {
@@ -73,7 +73,7 @@ public class MemoryMappedFileAppenderLocationTest {
}
final int LINESEP = System.lineSeparator().length();
assertEquals("Shrunk to actual used size", 474 + 2 * LINESEP, f.length());
-
+
String line1, line2, line3;
try (final BufferedReader reader = new BufferedReader(new FileReader(LOGFILE))) {
line1 = reader.readLine();
[15/18] logging-log4j2 git commit: LOG4J2-1343 minor test update:
call the right method
Posted by rp...@apache.org.
LOG4J2-1343 minor test update: call the right method
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/8b7028a9
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/8b7028a9
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/8b7028a9
Branch: refs/heads/master
Commit: 8b7028a9e6f7c93bd2a3fc2881d0ae7e32581aa7
Parents: 4dc2163
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 03:08:27 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 03:08:27 2016 +0900
----------------------------------------------------------------------
.../logging/log4j/core/appender/MemoryMappedFileManagerTest.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8b7028a9/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManagerTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManagerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManagerTest.java
index 828be94..4b06b52 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManagerTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManagerTest.java
@@ -30,7 +30,7 @@ import org.junit.Test;
/**
* Tests the MemoryMappedFileManager class.
- *
+ *
* @since 2.1
*/
public class MemoryMappedFileManagerTest {
@@ -51,7 +51,7 @@ public class MemoryMappedFileManagerTest {
for (int i = 0; i < 1000; i++) {
msg = ("Message " + i + "\n").getBytes();
- manager.write(msg, 0, msg.length);
+ manager.write(msg, 0, msg.length, false);
}
manager.release();
[03/18] logging-log4j2 git commit: LOG4J2-1343 modified
AbstractOutputStreamAppender to add support for subclasses to use the
garbage-free Layout mechanism
Posted by rp...@apache.org.
LOG4J2-1343 modified AbstractOutputStreamAppender to add support for subclasses to use the garbage-free Layout mechanism
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1e4dd880
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1e4dd880
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1e4dd880
Branch: refs/heads/master
Commit: 1e4dd880c4790993852abfa3769a96a20ded83ef
Parents: 49878b4
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 02:55:22 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 02:55:22 2016 +0900
----------------------------------------------------------------------
.../appender/AbstractOutputStreamAppender.java | 50 ++++++++++++++++----
1 file changed, 40 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1e4dd880/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java
index 7ed06d6..dcd0556 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java
@@ -20,10 +20,12 @@ import java.io.Serializable;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.layout.ByteBufferDestination;
+import org.apache.logging.log4j.core.util.Constants;
/**
* Appends log events as bytes to a byte output stream. The stream encoding is defined in the layout.
- *
+ *
* @param <M> The kind of {@link OutputStreamManager} under management
*/
public abstract class AbstractOutputStreamAppender<M extends OutputStreamManager> extends AbstractAppender {
@@ -41,7 +43,7 @@ public abstract class AbstractOutputStreamAppender<M extends OutputStreamManager
/**
* Instantiates a WriterAppender and set the output destination to a new {@link java.io.OutputStreamWriter}
* initialized with <code>os</code> as its {@link java.io.OutputStream}.
- *
+ *
* @param name The name of the Appender.
* @param layout The layout to format the message.
* @param manager The OutputStreamManager.
@@ -51,11 +53,16 @@ public abstract class AbstractOutputStreamAppender<M extends OutputStreamManager
super(name, filter, layout, ignoreExceptions);
this.manager = manager;
this.immediateFlush = immediateFlush;
+
+ if (Constants.ENABLE_DIRECT_ENCODERS) {
+ final ByteBufferDestination destination = manager.createByteBufferDestination(immediateFlush);
+ manager.setByteBufferDestination(destination);
+ }
}
/**
* Gets the immediate flush setting.
- *
+ *
* @return immediate flush.
*/
public boolean getImmediateFlush() {
@@ -64,7 +71,7 @@ public abstract class AbstractOutputStreamAppender<M extends OutputStreamManager
/**
* Gets the manager.
- *
+ *
* @return the manager.
*/
public M getManager() {
@@ -93,20 +100,43 @@ public abstract class AbstractOutputStreamAppender<M extends OutputStreamManager
* <p>
* Most subclasses of <code>AbstractOutputStreamAppender</code> will need to override this method.
* </p>
- *
+ *
* @param event The LogEvent.
*/
@Override
public void append(final LogEvent event) {
try {
- final byte[] bytes = getLayout().toByteArray(event);
- if (bytes != null && bytes.length > 0) {
- manager.write(bytes, this.immediateFlush || event.isEndOfBatch());
- }
+ tryAppend(event);
} catch (final AppenderLoggingException ex) {
- error("Unable to write to stream " + manager.getName() + " for appender " + getName());
+ error("Unable to write to stream " + manager.getName() + " for appender " + getName() + ": " + ex);
throw ex;
}
}
+ private void tryAppend(final LogEvent event) {
+ if (Constants.ENABLE_DIRECT_ENCODERS) {
+ directEncodeEvent(event);
+ } else {
+ writeByteArrayToManager(event);
+ }
+ }
+
+ protected void directEncodeEvent(final LogEvent event) {
+ synchronized (manager) {
+ getLayout().encode(event, manager.getByteBufferDestination());
+ if (!manager.isBufferedIO()) { // buffering was not requested by the user
+ manager.flushBuffer(); // we're not allowed to leave anything in the buffer: drain buffer into manager
+ }
+ if (this.immediateFlush || event.isEndOfBatch()) {
+ manager.flush();
+ }
+ }
+ }
+
+ protected void writeByteArrayToManager(final LogEvent event) {
+ final byte[] bytes = getLayout().toByteArray(event);
+ if (bytes != null && bytes.length > 0) {
+ manager.write(bytes, this.immediateFlush || event.isEndOfBatch());
+ }
+ }
}
[11/18] logging-log4j2 git commit: LOG4J2-1343 refactored
RollingRandomAccessFileManager to reuse the garbage-free Layout mechanism
defined in the superclass,
simplified logic when bytes to write exceed buffer size,
take unwritten buffered bytes into acc
Posted by rp...@apache.org.
LOG4J2-1343 refactored RollingRandomAccessFileManager to reuse the garbage-free Layout mechanism defined in the superclass, simplified logic when bytes to write exceed buffer size, take unwritten buffered bytes into account 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/cb33b0fe
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/cb33b0fe
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/cb33b0fe
Branch: refs/heads/master
Commit: cb33b0feb91f8be1c139270717da6ffc08513e36
Parents: 32e557b
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 03:05:35 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 03:05:35 2016 +0900
----------------------------------------------------------------------
.../rolling/RollingRandomAccessFileManager.java | 59 ++++++++++++++------
1 file changed, 43 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cb33b0fe/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 02c47e0..5c4ae10 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,8 @@ public class RollingRandomAccessFileManager extends RollingFileManager implement
private RandomAccessFile randomAccessFile;
private final ByteBuffer buffer;
private final ThreadLocal<Boolean> isEndOfBatch = new ThreadLocal<>();
+ private long drained;
+ private final long startSize;
public RollingRandomAccessFileManager(final RandomAccessFile raf, final String fileName, final String pattern,
final OutputStream os, final boolean append, final boolean immediateFlush, final int bufferSize,
@@ -52,6 +54,7 @@ public class RollingRandomAccessFileManager extends RollingFileManager implement
final String advertiseURI, final Layout<? extends Serializable> layout, final boolean writeHeader) {
super(fileName, pattern, os, append, size, time, policy, strategy, advertiseURI, layout, bufferSize,
writeHeader);
+ this.startSize = size;
this.isImmediateFlush = immediateFlush;
this.randomAccessFile = raf;
isEndOfBatch.set(Boolean.FALSE);
@@ -96,22 +99,40 @@ public class RollingRandomAccessFileManager extends RollingFileManager implement
@Override
protected synchronized void write(final byte[] bytes, int offset, int length, final boolean immediateFlush) {
- int chunk = 0;
- do {
- if (length > buffer.remaining()) {
- flush();
- }
- chunk = Math.min(length, buffer.remaining());
- buffer.put(bytes, offset, chunk);
- offset += chunk;
- length -= chunk;
- } while (length > 0);
+ if (length >= buffer.capacity()) {
+ // if request length exceeds buffer capacity, flush the buffer and write the data directly
+ flush();
+ writeToRandomAccessFile(bytes, offset, length);
+ return;
+ }
+ if (length > buffer.remaining()) {
+ flush();
+ }
+ buffer.put(bytes, offset, length);
if (immediateFlush || isImmediateFlush || isEndOfBatch.get() == Boolean.TRUE) {
flush();
}
}
+ private void writeToRandomAccessFile(final byte[] bytes, final int offset, final int length) {
+ try {
+ randomAccessFile.write(bytes, offset, length);
+ drained += buffer.limit(); // track file size
+ } catch (final IOException ex) {
+ final String msg = "Error writing to RandomAccessFile " + getName();
+ throw new AppenderLoggingException(msg, ex);
+ }
+ }
+
+ /**
+ * Returns the current size of the file.
+ * @return The size of the file in bytes.
+ */
+ public long getFileSize() {
+ return startSize + drained + getByteBufferDestination().getByteBuffer().position();
+ }
+
@Override
protected void createFileAfterRollover() throws IOException {
this.randomAccessFile = new RandomAccessFile(getFileName(), "rw");
@@ -124,12 +145,8 @@ public class RollingRandomAccessFileManager extends RollingFileManager implement
@Override
public synchronized void flush() {
buffer.flip();
- try {
- randomAccessFile.write(buffer.array(), 0, buffer.limit());
- size += buffer.limit(); // track file size
- } catch (final IOException ex) {
- final String msg = "Error writing to RandomAccessFile " + getName();
- throw new AppenderLoggingException(msg, ex);
+ if (buffer.limit() > 0) {
+ writeToRandomAccessFile(buffer.array(), 0, buffer.limit());
}
buffer.clear();
}
@@ -154,6 +171,16 @@ public class RollingRandomAccessFileManager extends RollingFileManager implement
return buffer.capacity();
}
+ /**
+ * Returns this {@code RollingRandomAccessFileManager}.
+ * @param immediateFlush ignored
+ * @return this {@code RollingRandomAccessFileManager}
+ */
+ @Override
+ protected ByteBufferDestination createByteBufferDestination(final boolean immediateFlush) {
+ return this;
+ }
+
@Override
public ByteBuffer getByteBuffer() {
return buffer;
[04/18] logging-log4j2 git commit: LOG4J2-1343 modified
OutputStreamManager to add support for subclasses to use the garbage-free
Layout mechanism
Posted by rp...@apache.org.
LOG4J2-1343 modified OutputStreamManager to add support for subclasses to use the garbage-free Layout mechanism
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/723c49f9
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/723c49f9
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/723c49f9
Branch: refs/heads/master
Commit: 723c49f96c3adbdf103eafef335a18879ba503c2
Parents: 1e4dd88
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 02:56:07 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 02:56:07 2016 +0900
----------------------------------------------------------------------
.../core/appender/OutputStreamManager.java | 51 ++++++++++++++++++++
1 file changed, 51 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/723c49f9/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
index cb1813e..34498fa 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamManager.java
@@ -18,8 +18,11 @@ package org.apache.logging.log4j.core.appender;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.ByteBuffer;
import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.layout.ByteBufferDestination;
+import org.apache.logging.log4j.core.util.Constants;
/**
* Manages an OutputStream so that it can be shared by multiple Appenders and will
@@ -29,6 +32,7 @@ public class OutputStreamManager extends AbstractManager {
private volatile OutputStream os;
protected final Layout<?> layout;
+ private ByteBufferDestination byteBufferDestination;
protected OutputStreamManager(final OutputStream os, final String streamName, final Layout<?> layout,
final boolean writeHeader) {
@@ -118,6 +122,7 @@ public class OutputStreamManager extends AbstractManager {
* @throws AppenderLoggingException if an error occurs.
*/
protected void write(final byte[] bytes, final int offset, final int length) {
+ flushBuffer();
write(bytes, offset, length, false);
}
@@ -149,6 +154,7 @@ public class OutputStreamManager extends AbstractManager {
* @throws AppenderLoggingException if an error occurs.
*/
protected void write(final byte[] bytes) {
+ flushBuffer();
write(bytes, 0, bytes.length, false);
}
@@ -159,10 +165,12 @@ public class OutputStreamManager extends AbstractManager {
* @throws AppenderLoggingException if an error occurs.
*/
protected void write(final byte[] bytes, boolean immediateFlush) {
+ flushBuffer();
write(bytes, 0, bytes.length, immediateFlush);
}
protected synchronized void close() {
+ flush();
final OutputStream stream = os; // access volatile field only once per method
if (stream == System.out || stream == System.err) {
return;
@@ -179,10 +187,53 @@ public class OutputStreamManager extends AbstractManager {
*/
public synchronized void flush() {
try {
+ flushBuffer();
os.flush();
} catch (final IOException ex) {
final String msg = "Error flushing stream " + getName();
throw new AppenderLoggingException(msg, ex);
}
}
+
+ /**
+ * Drains the ByteBufferDestination's buffer into the destination. By default this calls
+ * {@link OutputStreamManager#write(byte[], int, int, boolean)} with the buffer contents and the Appender's
+ * {@link AbstractOutputStreamAppender#immediateFlush} value.
+ * <p>
+ * This method has no effect if the garbage-free Layout encode mechanism is not enabled.
+ * </p>
+ */
+ protected void flushBuffer() {
+ if (Constants.ENABLE_DIRECT_ENCODERS) {
+ getByteBufferDestination().drain(getByteBufferDestination().getByteBuffer());
+ }
+ }
+
+ /**
+ * Subclasses that do buffered IO should override.
+ * @return this implementation always returns {@code false}
+ */
+ protected boolean isBufferedIO() {
+ return false;
+ }
+
+ public ByteBufferDestination getByteBufferDestination() {
+ return byteBufferDestination;
+ }
+
+ public void setByteBufferDestination(final ByteBufferDestination byteBufferDestination) {
+ this.byteBufferDestination = byteBufferDestination;
+ }
+
+ /**
+ * When the garbage-free Layout.encode mechanism is used, this method is called to create a ByteBufferDestination
+ * for this OutputStreamManager.
+ *
+ * @param immediateFlush the value to pass to the {@link #write(byte[], int, int, boolean)} method when the
+ * ByteBufferDestination is {@link ByteBufferDestination#drain(ByteBuffer) drained}
+ * @return a new ByteBufferDestination that drains into this OutputStreamManager
+ */
+ protected ByteBufferDestination createByteBufferDestination(final boolean immediateFlush) {
+ return new OutputStreamManagerDestination(immediateFlush, this);
+ }
}
[12/18] logging-log4j2 git commit: LOG4J2-1343
MemoryMappedFileAppender immediateFlush should be false to prevent spurious
remap() operations
Posted by rp...@apache.org.
LOG4J2-1343 MemoryMappedFileAppender immediateFlush should be false to prevent spurious remap() operations
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/875cec8f
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/875cec8f
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/875cec8f
Branch: refs/heads/master
Commit: 875cec8fc54d068e8ece37501d661540735e3e12
Parents: cb33b0f
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 03:06:26 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 03:06:26 2016 +0900
----------------------------------------------------------------------
.../logging/log4j/core/appender/MemoryMappedFileAppender.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/875cec8f/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileAppender.java
index a3cb25c..af3ff48 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileAppender.java
@@ -36,7 +36,7 @@ import org.apache.logging.log4j.core.util.Integers;
/**
* Memory Mapped File Appender.
- *
+ *
* @since 2.1
*/
@Plugin(name = "MemoryMappedFile", category = "Core", elementType = "appender", printObject = true)
@@ -102,7 +102,7 @@ public final class MemoryMappedFileAppender extends AbstractOutputStreamAppender
/**
* Returns the length of the memory mapped region.
- *
+ *
* @return the length of the memory mapped region
*/
public int getRegionLength() {
@@ -170,7 +170,7 @@ public final class MemoryMappedFileAppender extends AbstractOutputStreamAppender
return null;
}
- return new MemoryMappedFileAppender(name, layout, filter, manager, fileName, ignoreExceptions, isForce,
+ return new MemoryMappedFileAppender(name, layout, filter, manager, fileName, ignoreExceptions, false,
isAdvertise ? config.getAdvertiser() : null);
}
[06/18] logging-log4j2 git commit: LOG4J2-1343 FileManager should
honor the user-specified buffer size,
otherwise it re-uses the garbage-free Layout mechanism defined in the
superclass
Posted by rp...@apache.org.
LOG4J2-1343 FileManager should honor the user-specified buffer size, otherwise it re-uses the garbage-free Layout mechanism defined in the superclass
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3264915b
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3264915b
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3264915b
Branch: refs/heads/master
Commit: 3264915b9099712b35963648823778c5dd616d4a
Parents: dc78ca0
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 02:59:04 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 02:59:04 2016 +0900
----------------------------------------------------------------------
.../log4j/core/appender/FileManager.java | 33 ++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3264915b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
index 4de34ad..d147127 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileManager.java
@@ -23,12 +23,15 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
+import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.util.HashMap;
import java.util.Map;
import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.layout.ByteBufferDestination;
+import org.apache.logging.log4j.core.util.Constants;
/**
@@ -126,7 +129,7 @@ public class FileManager extends OutputStreamManager {
public boolean isLocking() {
return isLocking;
}
-
+
/**
* Returns the buffer size to use if the appender was configured with BufferedIO=true, otherwise returns a negative
* number.
@@ -137,6 +140,29 @@ public class FileManager extends OutputStreamManager {
}
/**
+ * Returns whether the user requested IO to be buffered.
+ * @return whether the buffer size is larger than zero.
+ */
+ @Override
+ protected boolean isBufferedIO() {
+ return bufferSize > 0;
+ }
+
+ /**
+ * Returns a OutputStreamManagerDestination with the user-requested buffer size.
+ * @param immediateFlush the value to pass to the {@link #write(byte[], int, int, boolean)} method when the
+ * ByteBufferDestination is {@link ByteBufferDestination#drain(ByteBuffer) drained}
+ * @return a OutputStreamManagerDestination with the user-requested buffer size
+ */
+ @Override
+ protected ByteBufferDestination createByteBufferDestination(final boolean immediateFlush) {
+ if (isBufferedIO()) {
+ return new OutputStreamManagerDestination(bufferSize, immediateFlush, this);
+ }
+ return new OutputStreamManagerDestination(immediateFlush, this);
+ }
+
+ /**
* FileManager's content format is specified by: <code>Key: "fileURI" Value: provided "advertiseURI" param</code>.
*
* @return Map of content format keys supporting FileManager
@@ -202,7 +228,10 @@ public class FileManager extends OutputStreamManager {
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; // signals to RollingFileManager not to use BufferedOutputStream
[05/18] logging-log4j2 git commit: LOG4J2-1343 SocketAppenders should
explicitly _not_ use the garbage-free Layout mechanism for now (until
solutions for the noted problems are found)
Posted by rp...@apache.org.
LOG4J2-1343 SocketAppenders should explicitly _not_ use the garbage-free Layout mechanism for now (until solutions for the noted problems are found)
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/dc78ca08
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/dc78ca08
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/dc78ca08
Branch: refs/heads/master
Commit: dc78ca08c4a32b95f44254718a7379347cc2ded4
Parents: 723c49f
Author: rpopma <rp...@apache.org>
Authored: Thu Apr 7 02:57:26 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Apr 7 02:57:26 2016 +0900
----------------------------------------------------------------------
.../log4j/core/appender/SocketAppender.java | 21 ++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/dc78ca08/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java
index 4a97189..6d0221e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java
@@ -22,6 +22,7 @@ import java.util.Map;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAliases;
@@ -74,7 +75,7 @@ public class SocketAppender extends AbstractOutputStreamAppender<AbstractSocketM
/**
* Creates a socket appender.
- *
+ *
* @param host
* The name of the host to connect to.
* @param port
@@ -122,10 +123,10 @@ public class SocketAppender extends AbstractOutputStreamAppender<AbstractSocketM
@PluginAttribute(value = "ignoreExceptions", defaultBoolean = true) final boolean ignoreExceptions,
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Filter") final Filter filter,
- @PluginAttribute(value = "advertise", defaultBoolean = false) final boolean advertise,
+ @PluginAttribute(value = "advertise", defaultBoolean = false) final boolean advertise,
@PluginConfiguration final Configuration config) {
// @formatter:on
-
+
if (layout == null) {
layout = SerializedLayout.createLayout();
}
@@ -149,7 +150,7 @@ public class SocketAppender extends AbstractOutputStreamAppender<AbstractSocketM
/**
* Creates a socket appender.
- *
+ *
* @param host
* The name of the host to connect to.
* @param portNum
@@ -200,7 +201,7 @@ public class SocketAppender extends AbstractOutputStreamAppender<AbstractSocketM
final String ignore,
Layout<? extends Serializable> layout,
final Filter filter,
- final String advertise,
+ final String advertise,
final Configuration config) {
// @formatter:on
boolean isFlush = Booleans.parseBoolean(immediateFlush, true);
@@ -216,7 +217,7 @@ public class SocketAppender extends AbstractOutputStreamAppender<AbstractSocketM
/**
* Creates an AbstractSocketManager for TCP, UDP, and SSL.
- *
+ *
* @throws IllegalArgumentException
* if the protocol cannot be handled.
*/
@@ -243,4 +244,12 @@ public class SocketAppender extends AbstractOutputStreamAppender<AbstractSocketM
throw new IllegalArgumentException(protocol.toString());
}
}
+
+ @Override
+ protected void directEncodeEvent(final LogEvent event) {
+ // Disable garbage-free logging for now:
+ // problem with TCP: synchronization on manager in Reconnector thread would give deadlock.
+ // problem with UDP: 8K buffer size means that largish messages get broken up into chunks
+ writeByteArrayToManager(event); // revert to classic (non-garbage free) logging
+ }
}