Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target::Pipe does not auto-flush like std{out/err} #278

Closed
miraclx opened this issue Sep 5, 2023 · 0 comments
Closed

Target::Pipe does not auto-flush like std{out/err} #278

miraclx opened this issue Sep 5, 2023 · 0 comments

Comments

@miraclx
Copy link

miraclx commented Sep 5, 2023

By default, env_logger writes to stderr using termcolor which defers to the std::io::Write implementation of std::io::Stderr. That implementation auto-flushes the buffer when a new line is found.

For most cases, this works fine because log auto-appends a new line at the end of the record.

But when using a custom sink (via Target::Pipe), for example - when writing to a file, io::Write::write is called, but io::Write::flush is never called.

This assumes that the io::Write::write implementation of the sink will flush the buffer because stdout & stderr do. But they're outliers in this. Writing does not imply flushing.

This also means if for whatever reason the last record isn't newline terminated, that record will be lost. Buffered in memory but never written to the destination.

@epage epage added this to the 0.11 milestone Nov 10, 2023
@epage epage closed this as completed in c088820 Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants