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.
By default,
env_logger
writes tostderr
usingtermcolor
which defers to thestd::io::Write
implementation ofstd::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, butio::Write::flush
is never called.This assumes that the
io::Write::write
implementation of the sink will flush the buffer becausestdout
&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.