Make FileLogger platform-independent: UTF-8 encoding and LF line separators - #208
Open
elharo wants to merge 4 commits into
Open
Make FileLogger platform-independent: UTF-8 encoding and LF line separators#208elharo wants to merge 4 commits into
elharo wants to merge 4 commits into
Conversation
elharo
marked this pull request as draft
September 2, 2026 11:59
Author
|
Hmm, this fails on JDK 25 Windows but in a strange way. Might be related: not clear why it would pass on UNix and fail on Windows |
elharo
commented
Sep 3, 2026
|
|
||
| /** | ||
| * The underlying file stream this logger writes to. | ||
| * The underlying file stream this logger writes to. It is always UTF-8 encoded so that |
Author
There was a problem hiding this comment.
remove "It is always UTF-8 encoded so that
* output is independent of the platform default charset."
as it should be assumed.
elharo
marked this pull request as ready for review
September 4, 2026 12:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Partially fixes #206.
Problem
FileLoggerwas not platform-independent in two ways:MirrorStreamWrapper.write(byte[], int, int)decoded mirrored bytes vianew String(b, off, len), and thePrintStreamencoded output with the platform default. On a host whose default charset is not UTF-8, non-ASCII text (e.g.café) was encoded/decoded as ISO-8859-1 instead of UTF-8, producing mojibake likecafé.System.lineSeparator(), so on Windows the output used\r\nwhile on Linux/macOS it used\n, making log files differ from platform to platform.Change
PrintStreamis now created withStandardCharsets.UTF_8(both the mirrored and non-mirrored paths), andMirrorStreamWrapperbuffers bytes and decodes them with UTF-8 on flush. Neither path consults the platform default charset anymore. Thewrite(int)byte path now also flows through the UTF-8-buffered mirror (previously it only worked for ASCII).\n) line separator inconsumeLineinstead ofSystem.lineSeparator(), so logs are byte-identical across Linux, macOS, and Windows.getPrintStream()is retained as required by theExecutionLoggerAPI; it is now UTF-8 encoded and its output is still mirrored.Tests
mirrorAndFileShouldUseUtf8, which writes non-ASCII content, asserts the mirror handler receives the correctly decodedcafé, and asserts the underlying file contains the exact UTF-8 bytes — verifying both the mirror and the file are UTF-8 independent of the host.System.lineSeparator()with\ninFileLoggerTestandTestMirrorHandlerto assert the new, platform-independent LF output.All 26 tests pass.