diff options
Diffstat (limited to 'mumlib/src')
| -rw-r--r-- | mumlib/src/lib.rs | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/mumlib/src/lib.rs b/mumlib/src/lib.rs index 5a51f37..b26db13 100644 --- a/mumlib/src/lib.rs +++ b/mumlib/src/lib.rs @@ -7,19 +7,29 @@ use log::*; pub const SOCKET_PATH: &str = "/var/tmp/mumd"; -pub fn setup_logger() { +pub fn setup_logger<T: Into<fern::Output>>(target: T, color: bool) { fern::Dispatch::new() - .format(|out, message, record| { + .format(move |out, message, record| { let message = message.to_string(); out.finish(format_args!( "{} {}:{}{}{}", //TODO runtime flag that disables color - match record.level() { - Level::Error => "ERROR".red(), - Level::Warn => "WARN ".yellow(), - Level::Info => "INFO ".normal(), - Level::Debug => "DEBUG".green(), - Level::Trace => "TRACE".normal(), + if color { + match record.level() { + Level::Error => "ERROR".red(), + Level::Warn => "WARN ".yellow(), + Level::Info => "INFO ".normal(), + Level::Debug => "DEBUG".green(), + Level::Trace => "TRACE".normal(), + } + } else { + match record.level() { + Level::Error => "ERROR", + Level::Warn => "WARN ", + Level::Info => "INFO ", + Level::Debug => "DEBUG", + Level::Trace => "TRACE", + }.normal() }, record.file().unwrap(), record.line().unwrap(), @@ -32,7 +42,7 @@ pub fn setup_logger() { )) }) .level(log::LevelFilter::Debug) - .chain(std::io::stderr()) + .chain(target.into()) .apply() .unwrap(); } |
