make log messages better

master
rasul 5 years ago
parent 7e30fb5d3a
commit fc36b7ec94

@ -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)
}
}

@ -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);
}
};
}

@ -15,7 +15,7 @@ pub struct Proc {
impl Proc {
pub fn start(app: App) -> Result<Self> {
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();
}
}

@ -42,8 +42,7 @@ fn restart_app(proc: Proc) -> Result<Proc> {
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<Proc>, holds: Option<i8>, 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) {

Loading…
Cancel
Save