diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-09-05 03:25:45 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-09-05 03:25:45 -0400 |
commit | fd2f77093812a19536487bbf6928d02fb9b1f372 (patch) | |
tree | a7b52eab4c41ef4fc039a5f80d01eeedae2d1985 /src/logging.rs | |
parent | 567a66d30fb86ad144e3deec256e27d05a611c2d (diff) | |
download | clinte-fd2f77093812a19536487bbf6928d02fb9b1f372.tar.gz |
letting errors flow up
Diffstat (limited to 'src/logging.rs')
-rw-r--r-- | src/logging.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/logging.rs b/src/logging.rs index d138a6c..b42c6b1 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -4,13 +4,14 @@ use std::fs::File; use chrono::offset::Utc; use simplelog::*; +use crate::error; use crate::user; lazy_static! { static ref FILE: String = format!("/tmp/clinte_{}.log", *user::NAME); } -pub fn init() { +pub fn init() -> error::Result<()> { // If the log file exists on startup, // move and timestamp it so we get a // fresh log file. @@ -19,7 +20,7 @@ pub fn init() { let time = Utc::now().to_rfc3339(); new_file.push_str("."); new_file.push_str(&time); - fs::rename(FILE.clone(), new_file).unwrap(); + fs::rename(FILE.clone(), new_file)?; } CombinedLogger::init(vec![ @@ -27,10 +28,12 @@ pub fn init() { WriteLogger::new( LevelFilter::Info, Config::default(), - File::create(FILE.clone()).unwrap(), + File::create(FILE.clone())?, ), ]) .expect("Unable to initialize logging"); + + Ok(()) } #[cfg(test)] @@ -43,7 +46,7 @@ mod tests { fn init_logs() { let blank = " ".bytes().collect::<Vec<u8>>(); fs::write(&*FILE, &blank).unwrap(); - init(); + init().unwrap(); info!("TEST LOG MESSAGE"); let logfile = fs::read_to_string(&*FILE).unwrap(); |