Skip to content

Commit

Permalink
feat: improved logging
Browse files Browse the repository at this point in the history
Signed-off-by: Sayan Paul <[email protected]>
  • Loading branch information
say-paul committed Oct 16, 2023
1 parent c0d93b4 commit 5996ca0
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ impl GreenbootConfig {
Ok(c) => {
config.max_reboot = match c.get_int("GREENBOOT_MAX_BOOT_ATTEMPTS") {
Ok(c) => c.try_into().unwrap_or_else(|e| {
log::warn!("{e}, using default value");
log::warn!("config format error:{e}, using default value");
config.max_reboot
}),
Err(e) => {
log::warn!("{e}, using default value");
log::warn!("error reading config:{e}, using default value");
config.max_reboot
}
}
}
Err(e) => log::warn!("{e}, using default value"),
Err(e) => log::warn!("config file error:{e}, using default value"),
}
config
}
Expand Down Expand Up @@ -112,8 +112,12 @@ fn run_diagnostics() -> Result<(), Error> {
log::info!("running required check {}", entry.to_string_lossy());
let output = Command::new("bash").arg("-C").arg(entry.clone()).output()?;
if !output.status.success() {
log::error!("required script {} failed!", entry.to_string_lossy());
log::error!("reason: {}", String::from_utf8_lossy(&output.stderr));
log::warn!(
"required script {} failed! \n{} \n{}",
entry.to_string_lossy(),
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
script_failure = true;
}
}
Expand All @@ -129,8 +133,14 @@ fn run_diagnostics() -> Result<(), Error> {
log::info!("running wanted check {}", entry.to_string_lossy());
let output = Command::new("bash").arg("-C").arg(entry.clone()).output()?;
if !output.status.success() {
log::warn!("wanted script {} failed!", entry.to_string_lossy());
log::warn!("reason: {}", String::from_utf8_lossy(&output.stderr));
log::warn!(
"wanted script {} failed! \n{} \n{}",
entry.to_string_lossy(),
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
} else {
log::warn!("wanted script {} success!", entry.to_string_lossy());
}
}
}
Expand All @@ -149,8 +159,12 @@ fn run_red() -> Result<(), Error> {
log::info!("running red check {}", entry.to_string_lossy());
let output = Command::new("bash").arg("-C").arg(entry.clone()).output()?;
if !output.status.success() {
log::warn!("red script: {} failed!", entry.to_string_lossy());
log::warn!("reason: {}", String::from_utf8_lossy(&output.stderr));
log::warn!(
"red script {} failed! \n{} \n{}",
entry.to_string_lossy(),
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
}
}
}
Expand All @@ -165,8 +179,12 @@ fn run_green() -> Result<(), Error> {
log::info!("running green check {}", entry.to_string_lossy());
let output = Command::new("bash").arg("-C").arg(entry.clone()).output()?;
if !output.status.success() {
log::warn!("green script {} failed!", entry.to_string_lossy());
log::warn!("reason: {}", String::from_utf8_lossy(&output.stderr));
log::warn!(
"green script {} failed! \n{} \n{}",
entry.to_string_lossy(),
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
}
}
}
Expand Down

0 comments on commit 5996ca0

Please sign in to comment.