Skip to content

Commit

Permalink
Fix single newline in logging output stream buffer (#52253)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rjernst authored Feb 12, 2020
1 parent 5bd9f2b commit c99210d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void flush() {
}
if (used == 0) {
// only windows \r was in the buffer
buffer.used = 0;
return;
}
log(new String(buffer.bytes, 0, used, StandardCharsets.UTF_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ public void testNull() {
// this test explicitly outputs the newlines instead of relying on println, to always test the unix behavior
public void testFlushOnUnixNewline() {
printStream.print("hello\n");
printStream.print("\n"); // newline by itself does not show up
printStream.print("world\n");
assertThat(loggingStream.lines, contains("hello", "world"));
}

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

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

0 comments on commit c99210d

Please sign in to comment.