diff --git a/src/lib.rs b/src/lib.rs index 1596a13f4..355f0a9cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,8 @@ use std::error::Error; +use log::error; + /// Prints a chain of errors to the user in a consistent manner. /// The user will see a clear chain of errors, followed by debug output /// for opening issues. @@ -19,10 +21,10 @@ pub fn cli_print_error_chain<'a>( ) { eprint!("Error: {component} exited with the following "); if top_error.source().is_none() { - eprintln!("error:"); - eprintln!(" {top_error}"); + error!("error:"); + error!(" {top_error}"); } else { - eprintln!("chain of errors:"); + error!("chain of errors:"); std::iter::successors(Some(top_error), |sub_error| { // Dereference necessary to mitigate rustc compiler bug. // See @@ -32,13 +34,13 @@ pub fn cli_print_error_chain<'a>( .for_each(|(level, error)| { // Special case: handling of HTTP Server responses in ch-remote if let Some(message) = display_modifier(level, 2, error) { - eprintln!("{message}"); + error!("{message}"); } else { - eprintln!(" {level}: {error}"); + error!(" {level}: {error}"); } }); } - eprintln!(); - eprintln!("Debug Info: {top_error:?}"); + error!(""); + error!("Debug Info: {top_error:?}"); } diff --git a/src/main.rs b/src/main.rs index 4a0fbe91f..101da1706 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ use std::{env, io}; use clap::{Arg, ArgAction, ArgGroup, ArgMatches, Command}; use event_monitor::event; use libc::EFD_NONBLOCK; -use log::{warn, LevelFilter}; +use log::{error, warn, LevelFilter}; use option_parser::OptionParser; use seccompiler::SeccompAction; use signal_hook::consts::SIGSYS; @@ -561,7 +561,7 @@ fn start_vmm(cmd_arguments: ArgMatches) -> Result, Error> { signal_hook::low_level::emulate_default_handler(SIGSYS).unwrap(); }) } - .map_err(|e| eprintln!("Error adding SIGSYS signal handler: {e}")) + .map_err(|e| error!("Error adding SIGSYS signal handler: {e}")) .ok(); } @@ -575,13 +575,13 @@ fn start_vmm(cmd_arguments: ArgMatches) -> Result, Error> { // dedicated signal handling thread we'll start in a bit. for sig in &vmm::vm::Vm::HANDLED_SIGNALS { if let Err(e) = block_signal(*sig) { - eprintln!("Error blocking signals: {e}"); + error!("Error blocking signals: {e}"); } } for sig in &vmm::Vmm::HANDLED_SIGNALS { if let Err(e) = block_signal(*sig) { - eprintln!("Error blocking signals: {e}"); + error!("Error blocking signals: {e}"); } }