From 47d3834a6e5b82e287b975fbf55939c6fd44ca02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Thu, 15 Oct 2020 21:02:44 +0200 Subject: add mumlib --- mumlib/src/lib.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 mumlib/src/lib.rs (limited to 'mumlib/src/lib.rs') diff --git a/mumlib/src/lib.rs b/mumlib/src/lib.rs new file mode 100644 index 0000000..ebf2019 --- /dev/null +++ b/mumlib/src/lib.rs @@ -0,0 +1,35 @@ +pub mod command; +pub mod state; + +use colored::*; +use log::*; + +pub fn setup_logger() { + fern::Dispatch::new() + .format(|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(), + }, + record.file().unwrap(), + record.line().unwrap(), + if message.chars().any(|e| e == '\n') { + "\n" + } else { + " " + }, + message + )) + }) + .level(log::LevelFilter::Debug) + .chain(std::io::stderr()) + .apply() + .unwrap(); +} -- cgit v1.2.1