From 79eae45196e89672a8d564e7595330cd7743fe17 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 9 Apr 2020 13:01:10 +0200 Subject: use log crate instead of own debug! macro This also does away with the scary unsafe{} blocks just to set/get the DEBUG flag. --- src/main.rs | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index f82e522..bbf4b70 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,12 +10,14 @@ use num_traits::cast::FromPrimitive; use regex::Regex; use structopt::StructOpt; use walkdir::{DirEntry, WalkDir}; +use log::debug; use evtclib::{AgentKind, AgentName, EventKind, Log}; +mod filters; mod guilds; +mod logger; mod output; -mod filters; mod csl; use csl::CommaSeparatedList; @@ -30,25 +32,6 @@ macro_rules! unwrap { }; } -macro_rules! debug { - ($($arg:tt)*) => { - if debug_enabled() { - use std::io::Write; - let stderr = ::std::io::stderr(); - let mut lock = stderr.lock(); - write!(lock, "[d] ").expect("debug write failed"); - writeln!(lock, $($arg)*).expect("debug write failed"); - } - } -} - -static mut DEBUG_ENABLED: bool = false; - -/// Return whether or not debug output should be enabled. -#[inline] -fn debug_enabled() -> bool { - unsafe { DEBUG_ENABLED } -} /// A program that allows you to search through all your evtc logs for specific /// people. @@ -244,8 +227,9 @@ fn main() { } if opt.debug { - // We haven't started any threads here yet, so this is fine. - unsafe { DEBUG_ENABLED = true }; + logger::initialize(log::Level::Debug); + } else { + logger::initialize(log::Level::Info); } if opt.guilds { -- cgit v1.2.3