mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-10-02 07:20:35 +00:00
appender: explicitly flush previous BufWriter before dropping (#1604)
## Motivation When a `RollingFileAppender` is refreshed, the previous `BufWriter` may encounter and suppress errors in `drop`. From https://doc.rust-lang.org/std/io/struct.BufWriter.html: > It is critical to call flush before BufWriter<W> is dropped. Though > dropping will attempt to flush the contents of the buffer, any errors > that happen in the process of dropping will be ignored. ## Solution Explicitly flush the previous buffer before dropping, printing any error to stderr.
This commit is contained in:
parent
f350c08a26
commit
024d6abcf2
@ -64,7 +64,12 @@ impl InnerAppender {
|
||||
self.next_date = self.rotation.next_date(&now);
|
||||
|
||||
match create_writer(&self.log_directory, &filename) {
|
||||
Ok(writer) => self.writer = writer,
|
||||
Ok(writer) => {
|
||||
if let Err(err) = self.writer.flush() {
|
||||
eprintln!("Couldn't flush previous writer: {}", err);
|
||||
}
|
||||
self.writer = writer
|
||||
}
|
||||
Err(err) => eprintln!("Couldn't create writer for logs: {}", err),
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user