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/08 12:54:37 UTC
[1/5] logging-log4j2 git commit: LOG4J2-1291 replace
ThreadLocal in AbstractStringLayout with plain field: the
ByteBufferDestination needs to be protected from concurrent access anyway
Repository: logging-log4j2
Updated Branches:
refs/heads/master 4d1d60de4 -> 34809a276
LOG4J2-1291 replace ThreadLocal<TextEncoderHelper> in AbstractStringLayout with plain field: the ByteBufferDestination needs to be protected from concurrent access anyway
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/19bafa4c
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/19bafa4c
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/19bafa4c
Branch: refs/heads/master
Commit: 19bafa4c8b24d07fa90cd5dc190c365ca38667f8
Parents: 4d1d60d
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 8 19:46:48 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 8 19:46:48 2016 +0900
----------------------------------------------------------------------
.../log4j/core/layout/AbstractStringLayout.java | 44 ++++++++++----------
1 file changed, 21 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/19bafa4c/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
index 84dbd69..19dbaf4 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
@@ -20,6 +20,7 @@ import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.StringLayout;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.apache.logging.log4j.core.util.Constants;
import org.apache.logging.log4j.core.util.StringEncoder;
import org.apache.logging.log4j.util.Strings;
@@ -58,7 +59,7 @@ public abstract class AbstractStringLayout extends AbstractLayout<String> implem
private static final ThreadLocal<StringBuilder> threadLocal = new ThreadLocal<>();
- private final ThreadLocal<TextEncoderHelper> textEncoderHelper = new ThreadLocal<>();
+ private final TextEncoderHelper textEncoderHelper;
/**
* Returns a {@code StringBuilder} that this Layout implementation can use to write the formatted log event to.
@@ -75,20 +76,6 @@ public abstract class AbstractStringLayout extends AbstractLayout<String> implem
return result;
}
- /**
- * Returns a {@code TextEncoderHelper} that this Layout implementation can use for encoding log events.
- *
- * @return a {@code TextEncoderHelper}
- */
- protected TextEncoderHelper getCachedTextEncoderHelper() {
- TextEncoderHelper result = textEncoderHelper.get();
- if (result == null) {
- result = new TextEncoderHelper(getCharset());
- textEncoderHelper.set(result);
- }
- return result;
- }
-
// LOG4J2-1151: If the built-in JDK 8 encoders are available we should use them.
private static boolean isPreJava8() {
final String version = System.getProperty("java.version");
@@ -120,37 +107,48 @@ public abstract class AbstractStringLayout extends AbstractLayout<String> implem
/**
* Builds a new layout.
- * @param charset the charset used to encode the header bytes, footer bytes and anything else that needs to be
+ * @param aCharset the charset used to encode the header bytes, footer bytes and anything else that needs to be
* converted from strings to bytes.
* @param header the header bytes
* @param footer the footer bytes
*/
- protected AbstractStringLayout(final Charset charset, final byte[] header, final byte[] footer) {
+ protected AbstractStringLayout(final Charset aCharset, final byte[] header, final byte[] footer) {
super(null, header, footer);
this.headerSerializer = null;
this.footerSerializer = null;
- this.charset = charset == null ? StandardCharsets.UTF_8 : charset;
+ this.charset = aCharset == null ? StandardCharsets.UTF_8 : aCharset;
this.charsetName = this.charset.name();
useCustomEncoding = isPreJava8()
- && (StandardCharsets.ISO_8859_1.equals(charset) || StandardCharsets.US_ASCII.equals(charset));
+ && (StandardCharsets.ISO_8859_1.equals(aCharset) || StandardCharsets.US_ASCII.equals(aCharset));
+ textEncoderHelper = Constants.ENABLE_DIRECT_ENCODERS ? new TextEncoderHelper(charset) : null;
}
/**
* Builds a new layout.
* @param config the configuration
- * @param charset the charset used to encode the header bytes, footer bytes and anything else that needs to be
+ * @param aCharset the charset used to encode the header bytes, footer bytes and anything else that needs to be
* converted from strings to bytes.
* @param headerSerializer the header bytes serializer
* @param footerSerializer the footer bytes serializer
*/
- protected AbstractStringLayout(final Configuration config, final Charset charset, final Serializer headerSerializer, final Serializer footerSerializer) {
+ protected AbstractStringLayout(final Configuration config, final Charset aCharset, final Serializer headerSerializer, final Serializer footerSerializer) {
super(config, null, null);
this.headerSerializer = headerSerializer;
this.footerSerializer = footerSerializer;
- this.charset = charset == null ? StandardCharsets.UTF_8 : charset;
+ this.charset = aCharset == null ? StandardCharsets.UTF_8 : aCharset;
this.charsetName = this.charset.name();
useCustomEncoding = isPreJava8()
- && (StandardCharsets.ISO_8859_1.equals(charset) || StandardCharsets.US_ASCII.equals(charset));
+ && (StandardCharsets.ISO_8859_1.equals(aCharset) || StandardCharsets.US_ASCII.equals(aCharset));
+ textEncoderHelper = Constants.ENABLE_DIRECT_ENCODERS ? new TextEncoderHelper(charset) : null;
+ }
+
+ /**
+ * Returns a {@code TextEncoderHelper} that this Layout implementation can use for encoding log events.
+ *
+ * @return a {@code TextEncoderHelper}
+ */
+ protected TextEncoderHelper getCachedTextEncoderHelper() {
+ return textEncoderHelper;
}
protected byte[] getBytes(final String s) {
[2/5] logging-log4j2 git commit: LOG4J2-1343 synchronize on the
ByteBufferDestination to protect against concurrent modification
Posted by rp...@apache.org.
LOG4J2-1343 synchronize on the ByteBufferDestination to protect against concurrent modification
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/acf8e347
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/acf8e347
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/acf8e347
Branch: refs/heads/master
Commit: acf8e3478e80b9222108ed6a428b9aa3cdc98a65
Parents: 19bafa4
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 8 19:49:23 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 8 19:49:23 2016 +0900
----------------------------------------------------------------------
.../log4j/core/layout/TextEncoderHelper.java | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/acf8e347/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
index 698072d..3e59c8a 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
@@ -51,11 +51,13 @@ public class TextEncoderHelper {
}
public void encodeText(final StringBuilder text, final ByteBufferDestination destination) {
- try {
- encodeText0(text, destination);
- } catch (final Exception ex) {
- logEncodeTextException(ex, text, destination);
- encodeTextFallBack(text, destination);
+ synchronized (destination) {
+ try {
+ encodeText0(text, destination);
+ } catch (final Exception ex) {
+ logEncodeTextException(ex, text, destination);
+ encodeTextFallBack(text, destination);
+ }
}
}
@@ -98,9 +100,11 @@ public class TextEncoderHelper {
}
public void encodeText(final CharBuffer charBuf, final ByteBufferDestination destination) {
- charsetEncoder.reset();
- final ByteBuffer byteBuf = destination.getByteBuffer();
- encode(charBuf, true, destination, byteBuf);
+ synchronized (destination) {
+ charsetEncoder.reset();
+ final ByteBuffer byteBuf = destination.getByteBuffer();
+ encode(charBuf, true, destination, byteBuf);
+ }
}
private ByteBuffer encode(final CharBuffer charBuf, final boolean endOfInput,
[5/5] logging-log4j2 git commit: use HeapByteBuffer rather than
DirectByteBuffer
Posted by rp...@apache.org.
use HeapByteBuffer rather than DirectByteBuffer
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/34809a27
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/34809a27
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/34809a27
Branch: refs/heads/master
Commit: 34809a2767474ef10ae55119608b60ae5b3ed552
Parents: 88563f2
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 8 19:52:42 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 8 19:52:42 2016 +0900
----------------------------------------------------------------------
.../logging/log4j/core/appender/RandomAccessFileManager.java | 2 +-
.../core/appender/rolling/RollingRandomAccessFileManager.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/34809a27/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 9b7fc91..cbd5eb1 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
@@ -54,7 +54,7 @@ public class RandomAccessFileManager extends OutputStreamManager implements Byte
this.randomAccessFile = file;
this.advertiseURI = advertiseURI;
this.isEndOfBatch.set(Boolean.FALSE);
- this.buffer = ByteBuffer.allocate(bufferSize);
+ this.buffer = ByteBuffer.wrap(new byte[bufferSize]);
}
/**
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/34809a27/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 5c4ae10..319cbd6 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
@@ -58,7 +58,7 @@ public class RollingRandomAccessFileManager extends RollingFileManager implement
this.isImmediateFlush = immediateFlush;
this.randomAccessFile = raf;
isEndOfBatch.set(Boolean.FALSE);
- this.buffer = ByteBuffer.allocate(bufferSize);
+ this.buffer = ByteBuffer.wrap(new byte[bufferSize]);
writeHeader();
}
[4/5] logging-log4j2 git commit: LOG4J2-1343 synchronize on the
ByteBufferDestination to protect against concurrent modification
Posted by rp...@apache.org.
LOG4J2-1343 synchronize on the ByteBufferDestination to protect against concurrent modification
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/88563f2f
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/88563f2f
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/88563f2f
Branch: refs/heads/master
Commit: 88563f2f28111901b2586c27b01be0f42d166bf0
Parents: 794af49
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 8 19:51:04 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 8 19:51:04 2016 +0900
----------------------------------------------------------------------
.../apache/logging/log4j/core/appender/OutputStreamManager.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/88563f2f/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 34498fa..aff8573 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
@@ -205,7 +205,10 @@ public class OutputStreamManager extends AbstractManager {
*/
protected void flushBuffer() {
if (Constants.ENABLE_DIRECT_ENCODERS) {
- getByteBufferDestination().drain(getByteBufferDestination().getByteBuffer());
+ final ByteBufferDestination destination = getByteBufferDestination();
+ synchronized (destination) {
+ destination.drain(destination.getByteBuffer());
+ }
}
}
[3/5] logging-log4j2 git commit: LOG4J2-1343 do not synchronize on
the appender Manager while converting the LogEvent to text: this may result
in deadlocks
Posted by rp...@apache.org.
LOG4J2-1343 do not synchronize on the appender Manager while converting the LogEvent to text: this may result in deadlocks
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/794af49a
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/794af49a
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/794af49a
Branch: refs/heads/master
Commit: 794af49a6f1ec1970c605bca04a38251684ab262
Parents: acf8e34
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 8 19:50:31 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 8 19:50:31 2016 +0900
----------------------------------------------------------------------
.../core/appender/AbstractOutputStreamAppender.java | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/794af49a/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 dcd0556..85faf43 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
@@ -122,14 +122,12 @@ public abstract class AbstractOutputStreamAppender<M extends OutputStreamManager
}
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();
- }
+ 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();
}
}