add some more coloring to log messages

master
rasul 5 years ago
parent ec7cefd023
commit 4e02a8d9fc

@ -1,5 +1,7 @@
use std::process::{Command, ExitStatus}; use std::process::{Command, ExitStatus};
use colored::Colorize;
use crate::result::Result; use crate::result::Result;
/// structure to define an app config /// structure to define an app config
@ -26,7 +28,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", &self.name); info!("[{}] starting", &self.name.yellow());
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();
@ -37,13 +39,13 @@ impl App {
if !output.stdout.is_empty() { if !output.stdout.is_empty() {
let s = String::from_utf8(output.stdout)?; let s = String::from_utf8(output.stdout)?;
for line in s.lines() { for line in s.lines() {
info!("[{}] stdout: {}", &self.name, line); info!("[{}] stdout: {}", &self.name.yellow(), line);
} }
} }
if !output.stderr.is_empty() { if !output.stderr.is_empty() {
let s = String::from_utf8(output.stderr)?; let s = String::from_utf8(output.stderr)?;
for line in s.lines() { for line in s.lines() {
info!("[{}] stderr: {}", &self.name, line); info!("[{}] stderr: {}", &self.name.yellow(), line);
} }
} }
Ok(()) Ok(())

@ -3,6 +3,7 @@ use std::fs::File;
use std::io::Read; use std::io::Read;
use std::path::PathBuf; use std::path::PathBuf;
use colored::Colorize;
use mio::{Poll, PollOpt, Ready}; use mio::{Poll, PollOpt, Ready};
use crate::app::App; use crate::app::App;
@ -56,7 +57,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!("[{}] failed to start: {:?}", &app.name, e); error!("[{}] failed to start: {:?}", &app.name.yellow(), e);
} }
} else { } else {
let name = app.name.clone(); let name = app.name.clone();
@ -75,7 +76,7 @@ impl Apps {
procs.push(proc); procs.push(proc);
} }
Err(e) => { Err(e) => {
error!("[{}] failed to start: {:?}", name, e); error!("[{}] failed to start: {:?}", name.yellow(), e);
} }
}; };
} }

@ -1,6 +1,8 @@
use std::convert::TryInto; use std::convert::TryInto;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use colored::Colorize;
use mio::Token; use mio::Token;
use mio_child_process::{CommandAsync, Process}; use mio_child_process::{CommandAsync, Process};
@ -15,7 +17,7 @@ pub struct Proc {
impl Proc { impl Proc {
pub fn start(app: App) -> Result<Self> { pub fn start(app: App) -> Result<Self> {
info!("[{}] starting", &app.name); info!("[{}] starting", &app.name.yellow());
let mut command = Command::new(&app.command); let mut command = Command::new(&app.command);
command.stdout(Stdio::piped()); command.stdout(Stdio::piped());
@ -35,7 +37,7 @@ impl Proc {
} }
pub fn stop(&mut self) { pub fn stop(&mut self) {
info!("[{}] stopping", &self.app.name); info!("[{}] stopping", &self.app.name.yellow());
let _ = self.process.kill(); let _ = self.process.kill();
} }
} }

@ -1,6 +1,8 @@
use std::boxed::Box; use std::boxed::Box;
use std::sync::mpsc::TryRecvError; use std::sync::mpsc::TryRecvError;
use colored::Colorize;
use mio::{Events, Poll, PollOpt, Ready, Token}; use mio::{Events, Poll, PollOpt, Ready, Token};
use mio_child_process::{ProcessEvent, StdioChannel}; use mio_child_process::{ProcessEvent, StdioChannel};
@ -42,7 +44,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, e); error!("[{}] error restarting: {:?}", name.yellow(), e);
Err(e) Err(e)
} }
} }
@ -96,19 +98,19 @@ fn run_loop(procs: Vec<Proc>, holds: Option<i8>, poll: Poll, signals: Signals) -
} }
// error starting or closing child process // error starting or closing child process
Ok(ProcessEvent::CommandError(e)) => { Ok(ProcessEvent::CommandError(e)) => {
error!("[{}] command error: {:?}", &proc.app.name, e) error!("[{}] command error: {:?}", &proc.app.name.yellow(), e)
} }
// error reading stdout or stderr // error reading stdout or stderr
Ok(ProcessEvent::IoError(channel, e)) => { Ok(ProcessEvent::IoError(channel, e)) => {
error!("[{}] io error on {:?}: {:?}", &proc.app.name, channel, e) error!("[{}] io error on {:?}: {:?}", &proc.app.name.yellow(), channel, e)
} }
// error doing utf8 translation // error doing utf8 translation
Ok(ProcessEvent::Utf8Error(channel, e)) => { Ok(ProcessEvent::Utf8Error(channel, e)) => {
error!("[{}] utf8 error on {:?}: {:?}", &proc.app.name, channel, e) error!("[{}] utf8 error on {:?}: {:?}", &proc.app.name.yellow(), channel, e)
} }
// process exited // process exited
Ok(ProcessEvent::Exit(status)) => { Ok(ProcessEvent::Exit(status)) => {
info!("[{}] exited with status {}", &proc.app.name, status); info!("[{}] exited with status {}", &proc.app.name.yellow(), 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