You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ck...@apache.org on 2021/08/23 19:20:08 UTC
[logging-log4j2] branch release-2.x updated: LOG4J2-3141: Deprecate
and stub out Manager.setEndOfBatch
This is an automated email from the ASF dual-hosted git repository.
ckozak pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/release-2.x by this push:
new b3ec097 LOG4J2-3141: Deprecate and stub out Manager.setEndOfBatch
b3ec097 is described below
commit b3ec097011ab551fef6c74d623ed332a6abe8be8
Author: Carter Kozak <ck...@apache.org>
AuthorDate: Mon Aug 23 14:20:34 2021 -0400
LOG4J2-3141: Deprecate and stub out Manager.setEndOfBatch
---
.../core/appender/MemoryMappedFileAppender.java | 18 ------------------
.../log4j/core/appender/MemoryMappedFileManager.java | 19 ++++++++++++++-----
.../core/appender/RandomAccessFileAppender.java | 20 --------------------
.../log4j/core/appender/RandomAccessFileManager.java | 19 ++++++++++++++-----
.../appender/RollingRandomAccessFileAppender.java | 8 --------
.../rolling/RollingRandomAccessFileManager.java | 19 ++++++++++++++-----
src/changes/changes.xml | 5 +++++
7 files changed, 47 insertions(+), 61 deletions(-)
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 54b8402..5efee5b 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
@@ -155,24 +155,6 @@ public final class MemoryMappedFileAppender extends AbstractOutputStreamAppender
}
/**
- * Write the log entry rolling over the file when required.
- *
- * @param event The LogEvent.
- */
- @Override
- public void append(final LogEvent event) {
-
- // Leverage the nice batching behaviour of async Loggers/Appenders:
- // we can signal the file manager that it needs to flush the buffer
- // to disk at the end of a batch.
- // From a user's point of view, this means that all log events are
- // _always_ available in the log file, without incurring the overhead
- // of immediateFlush=true.
- getManager().setEndOfBatch(event.isEndOfBatch()); // FIXME manager's EndOfBatch threadlocal can be deleted
- super.append(event); // TODO should only call force() if immediateFlush && endOfBatch?
- }
-
- /**
* Returns the file name this appender is associated with.
*
* @return The File name.
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 26c3edd..c2ae061 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
@@ -70,7 +70,6 @@ public class MemoryMappedFileManager extends OutputStreamManager {
private final int regionLength;
private final String advertiseURI;
private final RandomAccessFile randomAccessFile;
- private final ThreadLocal<Boolean> isEndOfBatch = new ThreadLocal<>();
private MappedByteBuffer mappedBuffer;
private long mappingOffset;
@@ -82,7 +81,6 @@ public class MemoryMappedFileManager extends OutputStreamManager {
this.randomAccessFile = Objects.requireNonNull(file, "RandomAccessFile");
this.regionLength = regionLength;
this.advertiseURI = advertiseURI;
- this.isEndOfBatch.set(Boolean.FALSE);
this.mappedBuffer = mmap(randomAccessFile.getChannel(), getFileName(), position, regionLength);
this.byteBuffer = mappedBuffer;
this.mappingOffset = position;
@@ -106,12 +104,23 @@ public class MemoryMappedFileManager extends OutputStreamManager {
regionLength, advertiseURI, layout), FACTORY));
}
+ /**
+ * No longer used, the {@link org.apache.logging.log4j.core.LogEvent#isEndOfBatch()} attribute is used instead.
+ * @return {@link Boolean#FALSE}.
+ * @deprecated end-of-batch on the event is used instead.
+ */
+ @Deprecated
public Boolean isEndOfBatch() {
- return isEndOfBatch.get();
+ return Boolean.FALSE;
}
- public void setEndOfBatch(final boolean endOfBatch) {
- this.isEndOfBatch.set(Boolean.valueOf(endOfBatch));
+ /**
+ * No longer used, the {@link org.apache.logging.log4j.core.LogEvent#isEndOfBatch()} attribute is used instead.
+ * This method is a no-op.
+ * @deprecated end-of-batch on the event is used instead.
+ */
+ @Deprecated
+ public void setEndOfBatch(@SuppressWarnings("unused") final boolean endOfBatch) {
}
@Override
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 6970126..5d0196b 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
@@ -142,26 +142,6 @@ public final class RandomAccessFileAppender extends AbstractOutputStreamAppender
}
/**
- * Write the log entry rolling over the file when required.
- *
- * @param event The LogEvent.
- */
- @Override
- public void append(final LogEvent event) {
-
- // Leverage the nice batching behaviour of async Loggers/Appenders:
- // we can signal the file manager that it needs to flush the buffer
- // to disk at the end of a batch.
- // From a user's point of view, this means that all log events are
- // _always_ available in the log file, without incurring the overhead
- // of immediateFlush=true.
- getManager().setEndOfBatch(event.isEndOfBatch()); // FIXME manager's EndOfBatch threadlocal can be deleted
-
- // LOG4J2-1292 utilize gc-free Layout.encode() method: taken care of in superclass
- super.append(event);
- }
-
- /**
* Returns the file name this appender is associated with.
*
* @return The File name.
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 86e7e62..0f85225 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
@@ -43,7 +43,6 @@ public class RandomAccessFileManager extends OutputStreamManager {
private final String advertiseURI;
private final RandomAccessFile randomAccessFile;
- private final ThreadLocal<Boolean> isEndOfBatch = new ThreadLocal<>();
protected RandomAccessFileManager(final LoggerContext loggerContext, final RandomAccessFile file, final String fileName,
final OutputStream os, final int bufferSize, final String advertiseURI,
@@ -51,7 +50,6 @@ public class RandomAccessFileManager extends OutputStreamManager {
super(loggerContext, os, fileName, false, layout, writeHeader, ByteBuffer.wrap(new byte[bufferSize]));
this.randomAccessFile = file;
this.advertiseURI = advertiseURI;
- this.isEndOfBatch.set(Boolean.FALSE);
}
/**
@@ -75,12 +73,23 @@ public class RandomAccessFileManager extends OutputStreamManager {
new FactoryData(append, immediateFlush, bufferSize, advertiseURI, layout, configuration), FACTORY));
}
+ /**
+ * No longer used, the {@link org.apache.logging.log4j.core.LogEvent#isEndOfBatch()} attribute is used instead.
+ * @return {@link Boolean#FALSE}.
+ * @deprecated end-of-batch on the event is used instead.
+ */
+ @Deprecated
public Boolean isEndOfBatch() {
- return isEndOfBatch.get();
+ return Boolean.FALSE;
}
- public void setEndOfBatch(final boolean endOfBatch) {
- this.isEndOfBatch.set(Boolean.valueOf(endOfBatch));
+ /**
+ * No longer used, the {@link org.apache.logging.log4j.core.LogEvent#isEndOfBatch()} attribute is used instead.
+ * This method is a no-op.
+ * @deprecated end-of-batch on the event is used instead.
+ */
+ @Deprecated
+ public void setEndOfBatch(@SuppressWarnings("unused") final boolean endOfBatch) {
}
@Override
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 f431f2d..840b791 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
@@ -239,14 +239,6 @@ public final class RollingRandomAccessFileAppender extends AbstractOutputStreamA
final RollingRandomAccessFileManager manager = getManager();
manager.checkRollover(event);
- // Leverage the nice batching behaviour of async Loggers/Appenders:
- // we can signal the file manager that it needs to flush the buffer
- // to disk at the end of a batch.
- // From a user's point of view, this means that all log events are
- // _always_ available in the log file, without incurring the overhead
- // of immediateFlush=true.
- manager.setEndOfBatch(event.isEndOfBatch()); // FIXME manager's EndOfBatch threadlocal can be deleted
-
// LOG4J2-1292 utilize gc-free Layout.encode() method: taken care of in superclass
super.append(event);
}
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 b956239..30d797e 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
@@ -46,7 +46,6 @@ public class RollingRandomAccessFileManager extends RollingFileManager {
private static final RollingRandomAccessFileManagerFactory FACTORY = new RollingRandomAccessFileManagerFactory();
private RandomAccessFile randomAccessFile;
- private final ThreadLocal<Boolean> isEndOfBatch = new ThreadLocal<>();
@Deprecated
public RollingRandomAccessFileManager(final LoggerContext loggerContext, final RandomAccessFile raf,
@@ -71,7 +70,6 @@ public class RollingRandomAccessFileManager extends RollingFileManager {
super(loggerContext, fileName, pattern, os, append, false, size, initialTime, policy, strategy, advertiseURI,
layout, filePermissions, fileOwner, fileGroup, writeHeader, ByteBuffer.wrap(new byte[bufferSize]));
this.randomAccessFile = raf;
- isEndOfBatch.set(Boolean.FALSE);
writeHeader();
}
@@ -111,12 +109,23 @@ public class RollingRandomAccessFileManager extends RollingFileManager {
filePermissions, fileOwner, fileGroup, configuration), FACTORY));
}
+ /**
+ * No longer used, the {@link org.apache.logging.log4j.core.LogEvent#isEndOfBatch()} attribute is used instead.
+ * @return {@link Boolean#FALSE}.
+ * @deprecated end-of-batch on the event is used instead.
+ */
+ @Deprecated
public Boolean isEndOfBatch() {
- return isEndOfBatch.get();
+ return Boolean.FALSE;
}
- public void setEndOfBatch(final boolean endOfBatch) {
- this.isEndOfBatch.set(Boolean.valueOf(endOfBatch));
+ /**
+ * No longer used, the {@link org.apache.logging.log4j.core.LogEvent#isEndOfBatch()} attribute is used instead.
+ * This method is a no-op.
+ * @deprecated end-of-batch on the event is used instead.
+ */
+ @Deprecated
+ public void setEndOfBatch(@SuppressWarnings("unused") final boolean endOfBatch) {
}
// override to make visible for unit tests
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 557574c..332fe36 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -85,6 +85,11 @@
<action issue="LOG4J2-3041" dev="rgoers" type="add">
Allow a PatternSelector to be specified on GelfLayout.
</action>
+ <action issue="LOG4J2-3141" dev="ckozak" type="add">
+ Avoid ThreadLocal overhead in RandomAccessFileAppender, RollingRandomAccessFileManager,
+ and MemoryMappedFileManager due to the unused setEndOfBatch and isEndOfBatch methods.
+ The methods on LogEvent are preferred.
+ </action>
<!-- FIXES -->
<action issue="LOG4J2-3083" dev="ckozak" type="fix">
log4j-slf4j-impl and log4j-slf4j18-impl correctly detect the calling class using both LoggerFactory.getLogger