Skip to content

Commit c07f464

Browse files
committed
Fix single newline in logging output stream buffer (#52253)
The buffer in LoggingOutputStream skips flushing when only a newline appears. However, if a windows newline appeared, the buffer length was not reset. This commit resets the length so the \r does not appear in the next logging message. closes #51838
1 parent 5dfe276 commit c07f464

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

server/src/main/java/org/elasticsearch/common/logging/LoggingOutputStream.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public void flush() {
9898
}
9999
if (used == 0) {
100100
// only windows \r was in the buffer
101+
buffer.used = 0;
101102
return;
102103
}
103104
log(new String(buffer.bytes, 0, used, StandardCharsets.UTF_8));

server/src/test/java/org/elasticsearch/common/logging/LoggingOutputStreamTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ public void testNull() {
8181
// this test explicitly outputs the newlines instead of relying on println, to always test the unix behavior
8282
public void testFlushOnUnixNewline() {
8383
printStream.print("hello\n");
84+
printStream.print("\n"); // newline by itself does not show up
8485
printStream.print("world\n");
8586
assertThat(loggingStream.lines, contains("hello", "world"));
8687
}
8788

8889
// this test explicitly outputs the newlines instead of relying on println, to always test the windows behavior
8990
public void testFlushOnWindowsNewline() {
9091
printStream.print("hello\r\n");
92+
printStream.print("\r\n"); // newline by itself does not show up
9193
printStream.print("world\r\n");
9294
assertThat(loggingStream.lines, contains("hello", "world"));
9395
}
@@ -102,7 +104,6 @@ public void testBufferExtension() {
102104
assertThat(loggingStream.threadLocal.get().bytes.length, equalTo(DEFAULT_BUFFER_LENGTH));
103105
}
104106

105-
@AwaitsFix( bugUrl = "https://github.com/elastic/elasticsearch/issues/51838")
106107
public void testMaxBuffer() {
107108
String longStr = randomAlphaOfLength(MAX_BUFFER_LENGTH);
108109
String extraLongStr = longStr + "OVERFLOW";

0 commit comments

Comments
 (0)