phanindra798 commented on code in PR #4473:
URL: https://github.com/apache/logging-log4j2/pull/4473#discussion_r4536378384
##########
log4j-core/src/main/java/org/apache/logging/log4j/core/appender/MemoryMappedFileManager.java:
##########
@@ -327,13 +442,13 @@ protected void flushBuffer(final ByteBuffer buffer) {
@Override
public ByteBuffer getByteBuffer() {
- return mappedBuffer;
+ return byteBuffer;
Review Comment:
Done. All tests now assert that no status warning or error is logged, so
`return mappedBuffer;` fails them. I also added a test where an empty event is
flushed before the file is opened (covers the `mappedBuffer != null` check in
`flush()`) and a byte array write test (covers the `byteBuffer` loop in
`write()`).
##########
log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileManager.java:
##########
@@ -136,13 +181,37 @@ public void setEndOfBatch(@SuppressWarnings("unused")
final boolean endOfBatch)
@Override
protected void writeToDestination(final byte[] bytes, final int offset,
final int length) {
try {
+ if (randomAccessFile == null) {
+ openFile();
+ }
randomAccessFile.write(bytes, offset, length);
} catch (final IOException ex) {
final String msg = "Error writing to RandomAccessFile " +
getName();
throw new AppenderLoggingException(msg, ex);
}
}
+ @SuppressFBWarnings(
+ value = "PATH_TRAVERSAL_IN",
+ justification = "The name of the accessed file is based on a
configuration value.")
+ private void openFile() throws IOException {
+ final File file = new File(getFileName());
+ FileUtils.makeParentDirs(file);
+ final RandomAccessFile raf = new RandomAccessFile(file, "rw");
+ try {
+ if (truncateOnOpen) {
+ raf.setLength(0);
+ } else {
+ raf.seek(raf.length());
+ }
+ } catch (final IOException e) {
+ Closer.closeSilently(raf);
+ throw e;
+ }
+ truncateOnOpen = false;
Review Comment:
Removed, thanks. I also removed the same unused reset in
`MemoryMappedFileManager.openAndMap()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]