From fc36b7ec94840b2f0baf55d3fae819e15d0e7e8c Mon Sep 17 00:00:00 2001 From: rasul Date: Fri, 13 Dec 2019 11:01:52 -0600 Subject: [PATCH] make log messages better --- src/app.rs | 5 +---- src/apps.rs | 6 ++---- src/proc.rs | 4 ++-- src/run.rs | 6 +++--- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/app.rs b/src/app.rs index eb8739e..6705374 100644 --- a/src/app.rs +++ b/src/app.rs @@ -26,7 +26,7 @@ pub struct App { impl App { /// start the application and wait for it to exit pub fn wait_start(&self) -> Result<()> { - info!("starting application {}", &self.name); + info!("[{}] starting", &self.name); let mut command = Command::new(&self.command); let args = self.args.as_ref(); @@ -55,13 +55,10 @@ impl App { /// see if the app should be restarted pub fn check_restart(&self, status: ExitStatus) -> bool { if status.success() { - info!("application exited: {}", &self.name); self.restart_on_success.unwrap_or(false) } else if let Some(code) = status.code() { - info!("application failed: {} ({})", &self.name, code); self.restart_on_failure.unwrap_or(false) } else { - info!("application terminated: {}", &self.name); self.restart_on_terminate.unwrap_or(false) } } diff --git a/src/apps.rs b/src/apps.rs index e8f5b9b..45e19df 100644 --- a/src/apps.rs +++ b/src/apps.rs @@ -56,8 +56,7 @@ impl Apps { for app in self.apps() { if app.wait.unwrap_or(false) { if let Err(e) = app.wait_start() { - error!("app failed to start: {}", &app.name); - error!("{:?}", e); + error!("[{}] failed to start: {:?}", &app.name, e); } } else { let name = app.name.clone(); @@ -76,8 +75,7 @@ impl Apps { procs.push(proc); } Err(e) => { - error!("app failed to start: {}", name); - error!("{:?}", e); + error!("[{}] failed to start: {:?}", name, e); } }; } diff --git a/src/proc.rs b/src/proc.rs index 951d639..8a9c667 100644 --- a/src/proc.rs +++ b/src/proc.rs @@ -15,7 +15,7 @@ pub struct Proc { impl Proc { pub fn start(app: App) -> Result { - info!("starting application {}", &app.name); + info!("[{}] starting", &app.name); let mut command = Command::new(&app.command); command.stdout(Stdio::piped()); @@ -35,7 +35,7 @@ impl Proc { } pub fn stop(&mut self) { - info!("stopping {}", &self.app.name); + info!("[{}] stopping", &self.app.name); let _ = self.process.kill(); } } diff --git a/src/run.rs b/src/run.rs index cbbe36c..233d3fb 100644 --- a/src/run.rs +++ b/src/run.rs @@ -42,8 +42,7 @@ fn restart_app(proc: Proc) -> Result { match Proc::start(app) { Ok(p) => Ok(p), Err(e) => { - error!("error restarting {}", name); - error!("{:?}", e); + error!("[{}] error restarting: {:?}", name, e); Err(e) } } @@ -65,7 +64,7 @@ fn process_event_data(channel: StdioChannel, data: String, app_name: &str) { StdioChannel::Stderr => "stderr", }; - info!("[{}] {}: {}", c, app_name, data.trim_end()); + info!("[{}] {}: {}", app_name, c, data.trim_end()); } /// run the main loop until out of holds @@ -109,6 +108,7 @@ fn run_loop(procs: Vec, holds: Option, poll: Poll, signals: Signals) - } // process exited Ok(ProcessEvent::Exit(status)) => { + info!("[{}]: exited with status {}", &proc.app.name, status); let hold = proc.app.hold.unwrap_or(false); if proc.app.check_restart(status) { if let Ok(p) = restart_app(proc) {