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:38 UTC
[logging-log4j2] branch master 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 master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/master by this push:
new 5bfad3b LOG4J2-3141: Deprecate and stub out Manager.setEndOfBatch
5bfad3b is described below
commit 5bfad3bea894745915ed62b6b4c97a9a7a6ff42c
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 e7f354f..79f26d9 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
@@ -152,24 +152,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 c972526..2a7714d 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 e03ad26..6372687 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
@@ -137,26 +137,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 56be44c..ba2c52b 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 dbc20f7..72eed24 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
@@ -235,14 +235,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 924a7c4..9be7e44 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<>();
/**
* @since 2.8.3
@@ -62,7 +61,6 @@ public class RollingRandomAccessFileManager extends RollingFileManager {
filePermissions, fileOwner, fileGroup,
writeHeader, ByteBuffer.wrap(new byte[bufferSize]));
this.randomAccessFile = raf;
- isEndOfBatch.set(Boolean.FALSE);
writeHeader();
}
@@ -102,12 +100,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 00363de..30f23a7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -224,6 +224,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