zlog: Ensure log file is flushed (#28923)
Closes #ISSUE Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
parent
9ea8a9a1d3
commit
63b4b60b79
3 changed files with 14 additions and 2 deletions
|
@ -130,6 +130,7 @@ pub fn init_panic_hook(
|
||||||
if let Some(panic_data_json) = serde_json::to_string_pretty(&panic_data).log_err() {
|
if let Some(panic_data_json) = serde_json::to_string_pretty(&panic_data).log_err() {
|
||||||
log::error!("{}", panic_data_json);
|
log::error!("{}", panic_data_json);
|
||||||
}
|
}
|
||||||
|
zlog::flush();
|
||||||
|
|
||||||
if !is_pty {
|
if !is_pty {
|
||||||
if let Some(panic_data_json) = serde_json::to_string(&panic_data).log_err() {
|
if let Some(panic_data_json) = serde_json::to_string(&panic_data).log_err() {
|
||||||
|
|
|
@ -152,8 +152,19 @@ pub fn submit(record: Record) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn flush() {
|
pub fn flush() {
|
||||||
|
if unsafe { ENABLED_SINKS_STDOUT } {
|
||||||
_ = std::io::stdout().lock().flush();
|
_ = 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);
|
struct ScopeFmt(Scope);
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ mod env_config;
|
||||||
pub mod filter;
|
pub mod filter;
|
||||||
pub mod sink;
|
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;
|
pub const SCOPE_DEPTH_MAX: usize = 4;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue