From 84ae58736098deb7a0137f3fe989c41774dddc7d Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Wed, 10 Oct 2018 12:55:32 -0400 Subject: [PATCH] Replace println! calls with logging --- Cargo.toml | 5 +++-- src/devices.rs | 4 ++-- src/hierarchies.rs | 2 +- src/lib.rs | 5 ++++- tests/pids.rs | 2 -- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3663abb..75657dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,10 +5,11 @@ repository = "https://github.com/levex/cgroups-rs" keywords = ["linux", "cgroup", "containers", "isolation"] categories = ["os", "api-bindings", "os::unix-apis"] license = "MIT OR Apache-2.0" -version = "0.0.3" -authors = ["Levente Kurusa "] +version = "0.1.0" +authors = ["Levente Kurusa ", "Sam Wilson "] [dependencies] +log = "0.4" [dev-dependencies] nix = "0.11.0" diff --git a/src/devices.rs b/src/devices.rs index 45dfc7a..195f7b4 100644 --- a/src/devices.rs +++ b/src/devices.rs @@ -265,7 +265,7 @@ impl DevicesController { s.lines().fold(Ok(Vec::new()), |acc, line| { let ls = line.to_string().split(|c| c == ' ' || c == ':').map(|x| x.to_string()).collect::>(); if acc.is_err() || ls.len() != 4 { - println!("line 204: acc: {:?}, ls: {:?}", acc, ls); + error!("allowed_devices: acc: {:?}, ls: {:?}", acc, ls); Err(CgroupError::ParseError) } else { let devtype = DeviceType::from_char(ls[0].chars().nth(0)); @@ -278,7 +278,7 @@ impl DevicesController { minor = Ok(-1); } if devtype.is_none() || major.is_err() || minor.is_err() || !DevicePermissions::is_valid(&ls[3]) { - println!("line 211: acc: {:?}, ls: {:?}, devtype: {:?}, major {:?} minor {:?} ls3 {:?}", + error!("allowed_devices: acc: {:?}, ls: {:?}, devtype: {:?}, major {:?} minor {:?} ls3 {:?}", acc, ls, devtype, major, minor, &ls[3]); Err(CgroupError::ParseError) } else { diff --git a/src/hierarchies.rs b/src/hierarchies.rs index 0bdb5f0..4db60c6 100644 --- a/src/hierarchies.rs +++ b/src/hierarchies.rs @@ -127,7 +127,7 @@ fn find_v1_mount() -> Option { let fstype = more_fields[0]; if fstype == "tmpfs" && more_fields[2].contains("ro") { let cgroups_mount = fields.nth(4).unwrap(); - println!("found cgroups at {:?}", cgroups_mount); + info!("found cgroups at {:?}", cgroups_mount); return Some(cgroups_mount.to_string()); } } diff --git a/src/lib.rs b/src/lib.rs index 86f0969..f827145 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,6 @@ +#[macro_use] +extern crate log; + use std::fs::File; use std::io::{BufRead, BufReader, Write}; use std::path::PathBuf; @@ -163,7 +166,7 @@ pub trait Controller { if self.verify_path() { match ::std::fs::create_dir(self.get_path()) { Ok(_) => (), - Err(e) => println!("error create_dir {:?}", e), + Err(e) => warn!("error create_dir {:?}", e), } } } diff --git a/tests/pids.rs b/tests/pids.rs index c892150..2a6a3a0 100644 --- a/tests/pids.rs +++ b/tests/pids.rs @@ -34,7 +34,6 @@ fn test_pids_current_is_zero() { { let pidcontroller: &PidController = cg.controller_of().unwrap(); let current = pidcontroller.get_pid_current(); - assert!(current.is_ok()); assert_eq!(current.unwrap(), 0); } cg.delete(); @@ -60,7 +59,6 @@ fn test_pid_events_is_not_zero() { { let pids: &PidController = cg.controller_of().unwrap(); let before = pids.get_pid_events(); - assert!(before.is_ok()); let before = before.unwrap(); match fork() {