aboutsummaryrefslogtreecommitdiffstats
path: root/mumlib/src
diff options
context:
space:
mode:
Diffstat (limited to 'mumlib/src')
-rw-r--r--mumlib/src/lib.rs28
1 files changed, 19 insertions, 9 deletions
diff --git a/mumlib/src/lib.rs b/mumlib/src/lib.rs
index d989a7e..40f37ef 100644
--- a/mumlib/src/lib.rs
+++ b/mumlib/src/lib.rs
@@ -5,19 +5,29 @@ pub mod state;
use colored::*;
use log::*;
-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(),
@@ -30,7 +40,7 @@ pub fn setup_logger() {
))
})
.level(log::LevelFilter::Debug)
- .chain(std::io::stderr())
+ .chain(target.into())
.apply()
.unwrap();
}