Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
zlog: Ensure log file is flushed (#28923)
Ben Kunkle63b4b60b7981
diff --git a/crates/zed/src/reliability.rs b/crates/zed/src/reliability.rsindex 86d17c83c12..6688417720e 100644--- a/crates/zed/src/reliability.rs+++ b/crates/zed/src/reliability.rs@@ -130,6 +130,7 @@ pub fn init_panic_hook(if let Some(panic_data_json) = serde_json::to_string_pretty(&panic_data).log_err() {log::error!("{}", panic_data_json);}+ zlog::flush();if !is_pty {if let Some(panic_data_json) = serde_json::to_string(&panic_data).log_err() {diff --git a/crates/zlog/src/sink.rs b/crates/zlog/src/sink.rsindex 6a2a041b2af..96a3b5750ac 100644--- a/crates/zlog/src/sink.rs+++ b/crates/zlog/src/sink.rs@@ -152,7 +152,18 @@ pub fn submit(record: Record) {}pub fn flush() {- _ = std::io::stdout().lock().flush();+ if unsafe { ENABLED_SINKS_STDOUT } {+ _ = std::io::stdout().lock().flush();+ }+ let mut file = ENABLED_SINKS_FILE.lock().unwrap_or_else(|handle| {+ ENABLED_SINKS_FILE.clear_poison();+ handle.into_inner()+ });+ if let Some(file) = file.as_mut() {+ if let Err(err) = file.flush() {+ eprintln!("Failed to flush log file: {}", err);+ }+ }}struct ScopeFmt(Scope);diff --git a/crates/zlog/src/zlog.rs b/crates/zlog/src/zlog.rsindex 9191335e41c..6c34f164d82 100644--- a/crates/zlog/src/zlog.rs+++ b/crates/zlog/src/zlog.rs@@ -5,7 +5,7 @@ mod env_config;pub mod filter;pub mod sink;-pub use sink::{init_output_file, init_output_stdout};+pub use sink::{flush, init_output_file, init_output_stdout};pub const SCOPE_DEPTH_MAX: usize = 4;