Skip to content

Flush console streams to preserve log order - #914

Open
arimu1 wants to merge 2 commits into
tinylog-org:v2.8from
arimu1:fix/849-log-order
Open

Flush console streams to preserve log order#914
arimu1 wants to merge 2 commits into
tinylog-org:v2.8from
arimu1:fix/849-log-order

Conversation

@arimu1

@arimu1 arimu1 commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix log entries appearing out of chronological order when using the default console writer with mixed severity levels (e.g. TRACE/DEBUG/INFO followed by WARN/ERROR).
  • Root cause: ConsoleWriter routes WARN and ERROR to System.err and lower levels to System.out. When System.out is block-buffered (common in IDE run consoles and piped output), stderr lines become visible before buffered stdout lines even though they were logged later.
  • Flush the target stream after each write and implement flush() for both stdout and stderr so entries appear in logging order.

Test plan

  • Added chronologicalOrderWithBufferedStandardOutputStream in ConsoleWriterTest reproducing the interleaved level sequence from Logs will not be written in correct order #849 with a non-autoflush stdout stream
  • mvn clean verify (requires JDK 9 per CONTRIBUTING.md)

Fixes #849

Made with Cursor

arimu1 added 2 commits August 15, 2026 09:47
Rewrite chronologicalOrderWithBufferedStandardOutputStream to observe
writes at the underlying OutputStream sink with a BufferedOutputStream
on stdout, so the test fails when ConsoleWriter.write() omits flush().
Update stale flush comment in errorOutputStreamForEmptyLogger.
@arimu1
arimu1 force-pushed the fix/849-log-order branch from 6a7e14c to f1bb87e Compare August 15, 2026 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Logs will not be written in correct order

1 participant