Replace println! calls with logging

This commit is contained in:
Sam Wilson
2018-10-10 12:55:32 -04:00
committed by Levente Kurusa
parent adc3323be4
commit 84ae587360
5 changed files with 10 additions and 8 deletions

View File

@@ -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 <lkurusa@acm.org>"]
version = "0.1.0"
authors = ["Levente Kurusa <lkurusa@acm.org>", "Sam Wilson <tecywiz121@hotmail.com>"]
[dependencies]
log = "0.4"
[dev-dependencies]
nix = "0.11.0"

View File

@@ -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::<Vec<String>>();
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 {

View File

@@ -127,7 +127,7 @@ fn find_v1_mount() -> Option<String> {
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());
}
}

View File

@@ -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),
}
}
}

View File

@@ -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() {