Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ public void write(int b) throws IOException {
public void flush() {
Buffer buffer = threadLocal.get();
if (buffer.used == 0) return;
log(new String(buffer.bytes, 0, buffer.used, StandardCharsets.UTF_8));
int used = buffer.used;
if (buffer.bytes[used - 1] == '\r') {
// windows case: remove the first part of newlines there too
--used;
}
log(new String(buffer.bytes, 0, used, StandardCharsets.UTF_8));
if (buffer.bytes.length != DEFAULT_BUFFER_LENGTH) {
threadLocal.set(new Buffer()); // reset size
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,17 @@ public void testNull() {
assertTrue(loggingStream.lines.isEmpty());
}

public void testFlushOnNewline() {
printStream.println("hello");
printStream.println("world");
// 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("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("world\r\n");
assertThat(loggingStream.lines, contains("hello", "world"));
}

Expand Down