diff --git a/Cargo.lock b/Cargo.lock index 3dfae7b..c2ffc21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -191,6 +191,7 @@ dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.9 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index e367017..0b37349 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,3 +18,4 @@ serde_derive = "1.0" tar = "0.4" flate2 = "1.0" dirs = "1.0" +log = "0.4" diff --git a/src/container.rs b/src/container.rs index f883c15..485f742 100644 --- a/src/container.rs +++ b/src/container.rs @@ -27,12 +27,12 @@ impl Container { pub fn prepare(&mut self) { self.image.pull().expect("Failed to cromwell pull"); - println!("Started initialize Container!"); + info!("Started initialize Container!"); let c_hosts = format!("{}/etc/hosts", self.image.get_full_path()); let c_resolv = format!("{}/etc/resolv.conf", self.image.get_full_path()); - println!("[INFO] Copying /etc/hosts to {}", c_hosts); - println!("[INFO] Copying /etc/resolv.conf {}", c_resolv); + info!("Copying /etc/hosts to {}", c_hosts); + info!("Copying /etc/resolv.conf {}", c_resolv); fs::copy("/etc/hosts", c_hosts).expect("Failed copy /etc/hosts: "); fs::copy("/etc/resolv.conf", c_resolv).expect("Failed copy /etc/resolv.conf: "); @@ -52,7 +52,7 @@ impl Container { pub fn run(&self) { match fork() { Ok(ForkResult::Parent { child, .. }) => { - println!("[INFO] container pid: {}", child); + info!("container pid: {}", child); match waitpid(child, None).expect("waitpid faild") { WaitStatus::Exited(_, _) => {} @@ -67,7 +67,7 @@ impl Container { eprintln!("{:?}", why.kind()); }); - println!("[INFO] Mount procfs ... "); + info!("Mount procfs ... "); mounts::mount_proc().expect("mount procfs failed"); let cmd = CString::new(self.command.clone()).unwrap(); @@ -83,7 +83,7 @@ impl Container { ) .expect("execution faild."); } - Err(_) => eprintln!("[ERROR] Fork failed"), + Err(_) => error!("Fork failed"), } } diff --git a/src/image.rs b/src/image.rs index 2693935..c784f10 100644 --- a/src/image.rs +++ b/src/image.rs @@ -37,7 +37,7 @@ impl Image { } pub fn tar_archive(&mut self, path: &str) -> io::Result<()> { - println!("[INFO] tar unpack start {}", path); + info!("tar unpack start {}", path); let tar_gz = File::open(&path).expect(""); let tar = GzDecoder::new(tar_gz); let mut ar = Archive::new(tar); @@ -49,10 +49,10 @@ impl Image { fs::remove_dir_all(&image_path)?; } - println!("[INFO] mkdir {}", image_path); + info!("mkdir {}", image_path); std::fs::create_dir(&image_path)?; - println!("[INFO] unpacking {}", image_path); + info!("unpacking {}", image_path); match ar.unpack(&image_path) { Ok(_) => Ok(()), @@ -101,8 +101,8 @@ impl Image { Value::Array(fs_layers) => { for fs_layer in fs_layers { match self.download(token.to_string(), &fs_layer) { - Ok(_) => println!("[INFO] image download successed"), - Err(e) => eprintln!("[ERROR] {}", e), + Ok(_) => info!("[INFO] image download successed"), + Err(e) => error!("[ERROR] {}", e), } } } diff --git a/src/main.rs b/src/main.rs index f8b1a9d..a925d71 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ #[macro_use] extern crate serde_derive; +#[macro_use] +extern crate log; use std::process::exit;