diff options
author | Ben Morrison <ben@gbmor.dev> | 2020-05-26 21:48:36 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2020-05-26 23:54:09 -0400 |
commit | f79e97f5c3cae593aefaf7b02664e961572092c8 (patch) | |
tree | 6a95e6908e848adce240ed1d6f1788b2936ceee5 /src/logging.rs | |
parent | fdf322b2d2e93428768e9207f1c62a866e7e8ef4 (diff) | |
download | clinte-f79e97f5c3cae593aefaf7b02664e961572092c8.tar.gz |
removed panics from logging initialization
Diffstat (limited to 'src/logging.rs')
-rw-r--r-- | src/logging.rs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/logging.rs b/src/logging.rs index 346a7ab..5d3f378 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -2,19 +2,25 @@ use std::fs::OpenOptions; use simplelog::*; +use crate::conf; use crate::error; +use crate::user; -pub fn init(path: &str) -> error::Result<()> { - let logfile = match OpenOptions::new().append(true).create(true).open(path) { - Err(e) => { - panic!("Could not open log file: {}", e); - } - Ok(f) => f, - }; +pub fn checked_init() { + let logfile = format!("/tmp/clinte_{}.log", *user::NAME); - if let Err(e) = WriteLogger::init(LevelFilter::Info, Config::default(), logfile) { - panic!("Could not initiate logging: {}", e); + if let Err(e) = init(&logfile) { + log::error!("Couldn't initialize logging. Exiting."); + if *conf::DEBUG { + log::error!("--> {}", e); + } + std::process::exit(1); } +} + +fn init(path: &str) -> error::Result<()> { + let logfile = OpenOptions::new().append(true).create(true).open(path)?; + WriteLogger::init(LevelFilter::Info, Config::default(), logfile)?; Ok(()) } |