Add IO::Buffered#flush_on_newline
back and set it to true for non-tty
#8935
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.
Reverts #7470
Fixes #7431 (somehow)
Before #7470 if you output to the console and redirected that output to somewhere else, for example a file, then you would see output right after each line was emitted.
Once we merged #7470 you would only see output after the IO buffer was full and it was flushed.
That meant that if you did
tail -f
on that file you wouldn't see new lines appended to it immediately. I believe this is not very intuitive. If you don't output enough data you might think something is broken and lose a lot of time debugging this.This PR reverts the behavior back to how it was before.
This is slower, but you still have the option to make is faster (if you don't care about not seeing "correct" output using
tail -f
) by doing:If we don't add this method back, the only options you have are:
With
flush_on_newline
it's not fast but it's also not very slow. So I think this is a good default.💭 We could also consider having an environment variable, for example
CRYSTAL_STDOUT_FLUSH_ON_NEWLINE
so you can control, at runtime, how the program behaves (on startup). That means that you can compile your program once and control how it behaves later on. But I didn't include this here. We can discuss it in a different issue if needed, and do it in a separate PR.Please 👍 if you agree with this change, 👎 if not.