From bc053f1b13191a77cc26a0abbca70ddb2860eaf4 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 4 Feb 2020 11:16:31 +0000 Subject: [PATCH] main: Ignore error on log writing A previous version of this change attempted to avoid panicking by not using .expect() when handling an error when attempting to write to the log file. Unfortunately the macro eprintln!() that was used to replace the .expect() also has the behaviour of panicking if stderr cannot be used. Instead swallow the error completely as if writing to the log has failed at logging time it is almost certainly the case that any message about the log would also not be seen. Signed-off-by: Rob Bradford --- src/main.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4916b7037..3e6ab8db5 100755 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,7 @@ impl log::Log for Logger { let now = std::time::Instant::now(); let duration = now.duration_since(self.start); - if let Err(e) = if record.file().is_some() && record.line().is_some() { + if record.file().is_some() && record.line().is_some() { writeln!( *(*(self.output.lock().unwrap())), "cloud-hypervisor: {:?}: {}:{}:{} -- {}", @@ -57,9 +57,7 @@ impl log::Log for Logger { record.target(), record.args() ) - } { - eprintln!("Error writing log output: {:?}", e); - } + }.ok(); } fn flush(&self) {} }