~gbmor/clinte

f79e97f5c3cae593aefaf7b02664e961572092c8 — Ben Morrison 1 year, 2 months ago fdf322b
removed panics from logging initialization
1 files changed, 15 insertions(+), 9 deletions(-)

M src/logging.rs
M src/logging.rs => src/logging.rs +15 -9
@@ 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(())
}