mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: replace eprintln with log::error
Unify log formatting and printing as `eprintln!` and `log::error!` would be used alongside each other. When using e.g. `env_logger` lines printed with `eprintln!` would lack formatting / colors. Currently only relevant in `ch-remote` + `cli_print_error_chain`. Note that the replaced messages now also end up in the logfile of `cloud-hypervisor` when configured and not any longer in stderr. Signed-off-by: Maximilian Güntner <code@mguentner.de>
This commit is contained in:
committed by
Bo Chen
parent
19dc733267
commit
50b33db718
16
src/lib.rs
16
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 <https://github.com/rust-lang/rust/issues/141673>
|
||||
@@ -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:?}");
|
||||
}
|
||||
|
||||
@@ -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<Option<String>, 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<Option<String>, 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}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user