From b3953ae1a8be6355bc9a40404d058e52b1abc42a Mon Sep 17 00:00:00 2001 From: Bo Maryniuk Date: Tue, 22 Oct 2024 19:54:38 +0200 Subject: [PATCH] Add prefix implementation --- .../src/reactor/handlers/cstr_stdhdl.rs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/libsysinspect/src/reactor/handlers/cstr_stdhdl.rs b/libsysinspect/src/reactor/handlers/cstr_stdhdl.rs index 9a98b0d7..5248c3e2 100644 --- a/libsysinspect/src/reactor/handlers/cstr_stdhdl.rs +++ b/libsysinspect/src/reactor/handlers/cstr_stdhdl.rs @@ -15,6 +15,20 @@ pub struct ConstraintHandler { config: EventConfig, } +impl ConstraintHandler { + /// Get prefix from the configuration + fn get_prefix(&self) -> String { + let mut prefix = "".to_string(); + if let Some(config) = self.config() { + if let Some(p) = config.as_string("prefix") { + prefix = format!("{} - ", p.cyan()); + } + } + + prefix + } +} + /// STDOUT event handler. It just outputs the action response to a log. impl EventHandler for ConstraintHandler { fn new(eid: String, cfg: EventConfig) -> Self @@ -36,14 +50,16 @@ impl EventHandler for ConstraintHandler { return; } + let prefix = self.get_prefix(); + if !evt.errors.has_errors() { - log::info!("All constraints {}", "passed".bright_green().bold()); + log::info!("{}All constraints {}", prefix, "passed".bright_green().bold()); return; } log::info!("{}", evt.errors.descr()); for f in evt.errors.failures() { - log::error!("{}: {}", f.title.yellow(), f.msg); + log::error!("{}{}: {}", prefix, f.title.yellow(), f.msg); } }