Skip to content

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

@miraclx

Description

@miraclx

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions