From 523355a2d12b0a9c052f4d9ce2e8a26ad00cf719 Mon Sep 17 00:00:00 2001 From: Matt Kline Date: Mon, 27 Sep 2021 00:24:35 -0700 Subject: [PATCH] TermLogger: Flush each entry The log crate holds the logger as a `static mut` reference which isn't dropped at program exit: https://doc.rust-lang.org/reference/items/static-items.html Sadly, this means we can't rely on the BufferedStandardStreams flushing themselves on the way out, so to avoid the Case of the Missing 8k, flush each entry. Fixes #80 --- Cargo.toml | 2 +- src/loggers/termlog.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ffac211f..3d8e8dd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "simplelog" -version = "0.10.1" +version = "0.10.2" edition = "2018" authors = ["Drakulix "] description = "A simple and easy-to-use logging facility for Rust's log crate" diff --git a/src/loggers/termlog.rs b/src/loggers/termlog.rs index a16f0030..ffc37527 100644 --- a/src/loggers/termlog.rs +++ b/src/loggers/termlog.rs @@ -159,7 +159,14 @@ impl TermLogger { write_location(record, term_lock)?; } - write_args(record, term_lock) + write_args(record, term_lock)?; + + // The log crate holds the logger as a `static mut`, which isn't dropped + // at program exit: https://doc.rust-lang.org/reference/items/static-items.html + // Sadly, this means we can't rely on the BufferedStandardStreams flushing + // themselves on the way out, so to avoid the Case of the Missing 8k, + // flush each entry. + term_lock.flush() } fn try_log(&self, record: &Record<'_>) -> Result<(), Error> {