make log messages better

master
rasul 5 years ago
parent 7e30fb5d3a
commit fc36b7ec94

@ -26,7 +26,7 @@ pub struct App {
impl App { impl App {
/// start the application and wait for it to exit /// start the application and wait for it to exit
pub fn wait_start(&self) -> Result<()> { pub fn wait_start(&self) -> Result<()> {
info!("starting application {}", &self.name); info!("[{}] starting", &self.name);
let mut command = Command::new(&self.command); let mut command = Command::new(&self.command);
let args = self.args.as_ref(); let args = self.args.as_ref();
@ -55,13 +55,10 @@ impl App {
/// see if the app should be restarted /// see if the app should be restarted
pub fn check_restart(&self, status: ExitStatus) -> bool { pub fn check_restart(&self, status: ExitStatus) -> bool {
if status.success() { if status.success() {
info!("application exited: {}", &self.name);
self.restart_on_success.unwrap_or(false) self.restart_on_success.unwrap_or(false)
} else if let Some(code) = status.code() { } else if let Some(code) = status.code() {
info!("application failed: {} ({})", &self.name, code);
self.restart_on_failure.unwrap_or(false) self.restart_on_failure.unwrap_or(false)
} else { } else {
info!("application terminated: {}", &self.name);
self.restart_on_terminate.unwrap_or(false) self.restart_on_terminate.unwrap_or(false)
} }
} }

@ -56,8 +56,7 @@ impl Apps {
for app in self.apps() { for app in self.apps() {
if app.wait.unwrap_or(false) { if app.wait.unwrap_or(false) {
if let Err(e) = app.wait_start() { if let Err(e) = app.wait_start() {
error!("app failed to start: {}", &app.name); error!("[{}] failed to start: {:?}", &app.name, e);
error!("{:?}", e);
} }
} else { } else {
let name = app.name.clone(); let name = app.name.clone();
@ -76,8 +75,7 @@ impl Apps {
procs.push(proc); procs.push(proc);
} }
Err(e) => { Err(e) => {
error!("app failed to start: {}", name); error!("[{}] failed to start: {:?}", name, e);
error!("{:?}", e);
} }
}; };
} }

@ -15,7 +15,7 @@ pub struct Proc {
impl Proc { impl Proc {
pub fn start(app: App) -> Result<Self> { pub fn start(app: App) -> Result<Self> {
info!("starting application {}", &app.name); info!("[{}] starting", &app.name);
let mut command = Command::new(&app.command); let mut command = Command::new(&app.command);
command.stdout(Stdio::piped()); command.stdout(Stdio::piped());
@ -35,7 +35,7 @@ impl Proc {
} }
pub fn stop(&mut self) { pub fn stop(&mut self) {
info!("stopping {}", &self.app.name); info!("[{}] stopping", &self.app.name);
let _ = self.process.kill(); let _ = self.process.kill();
} }
} }

@ -42,8 +42,7 @@ fn restart_app(proc: Proc) -> Result<Proc> {
match Proc::start(app) { match Proc::start(app) {
Ok(p) => Ok(p), Ok(p) => Ok(p),
Err(e) => { Err(e) => {
error!("error restarting {}", name); error!("[{}] error restarting: {:?}", name, e);
error!("{:?}", e);
Err(e) Err(e)
} }
} }
@ -65,7 +64,7 @@ fn process_event_data(channel: StdioChannel, data: String, app_name: &str) {
StdioChannel::Stderr => "stderr", 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 /// 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 // process exited
Ok(ProcessEvent::Exit(status)) => { Ok(ProcessEvent::Exit(status)) => {
info!("[{}]: exited with status {}", &proc.app.name, status);
let hold = proc.app.hold.unwrap_or(false); let hold = proc.app.hold.unwrap_or(false);
if proc.app.check_restart(status) { if proc.app.check_restart(status) {
if let Ok(p) = restart_app(proc) { if let Ok(p) = restart_app(proc) {

Loading…
Cancel
Save