ion-rust
ion-rust copied to clipboard
Does IonWriter::flush() flush() the underlying file?
Our app is logging from a panic hook, and sometimes the data makes it to disk, sometimes it doesn't. In the below code, both closed!!! and flushed!!! are printed, but the data does not make it to disk.
Should IonWriter::flush() call flush() or even sync() on the underlying file?
If not, it would be great if it would flush() and allow calling code to sync() the underlying file.
Thanks!
#[track_caller]
fn log_panic_info(panic_info: &panic::PanicHookInfo<'_>) {
if let Some(mutex) = LOG.get() {
if let Ok(mut log) = mutex.lock() {
{
let mut entry_writer = EntryWriter::new(&mut log, EntryKind::Panic);
let mut panic_info_writer = entry_writer.ion_list_writer.struct_writer().expect("panic_info error: panic_info_writer creation failed");
if let Some(payload) = panic_info.payload().downcast_ref::<&str>() {
let _ = panic_info_writer.write("payload", payload).map_err(|err| eprintln!("{err:?} at {}:{} in {}", file!(), line!(), module_path!()));
} else if let Some(payload) = panic_info.payload().downcast_ref::<String>() {
let _ = panic_info_writer.write("payload", payload.as_str()).map_err(|err| eprintln!("{err:?} at {}:{} in {}", file!(), line!(), module_path!()));
} else {
let _ = panic_info_writer.write("payload", format!("{:?}", panic_info.payload()).as_str()).map_err(|err| eprintln!("{err:?} at {}:{} in {}", file!(), line!(), module_path!()));
}
...
let _ = panic_info_writer.close().map_err(|err| eprintln!("{err:?} at {}:{} in {}", file!(), line!(), module_path!()));
let _ = entry_writer.ion_list_writer.close().map_err(|err| eprintln!("{err:?} at {}:{} in {}", file!(), line!(), module_path!()));
eprintln!("closed!!!");
}
let _ = log.ion_writer.flush();
eprintln!("flushed!!!");
}
}
}