Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Implemented using crate log
Browse files Browse the repository at this point in the history
  • Loading branch information
guni1192 committed Feb 14, 2019
1 parent aaec519 commit d2e5088
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ serde_derive = "1.0"
tar = "0.4"
flate2 = "1.0"
dirs = "1.0"
log = "0.4"
12 changes: 6 additions & 6 deletions src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: ");
Expand All @@ -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(_, _) => {}
Expand All @@ -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();
Expand All @@ -83,7 +83,7 @@ impl Container {
)
.expect("execution faild.");
}
Err(_) => eprintln!("[ERROR] Fork failed"),
Err(_) => error!("Fork failed"),
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(()),
Expand Down Expand Up @@ -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),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate log;

use std::process::exit;

Expand Down

0 comments on commit d2e5088

Please sign in to comment.