aboutsummaryrefslogtreecommitdiffstats
path: root/mumlib/src/lib.rs
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-10-15 21:02:44 +0200
committerGustav Sörnäs <gustav@sornas.net>2020-10-15 21:02:44 +0200
commit47d3834a6e5b82e287b975fbf55939c6fd44ca02 (patch)
tree7e3a79a2ab9ebf7fc3b0bbc5ac575e086e86eea2 /mumlib/src/lib.rs
parentde856d5e43ecadcd876bdf03800ecc5421347872 (diff)
downloadmum-47d3834a6e5b82e287b975fbf55939c6fd44ca02.tar.gz
add mumlib
Diffstat (limited to 'mumlib/src/lib.rs')
-rw-r--r--mumlib/src/lib.rs35
1 files changed, 35 insertions, 0 deletions
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();
+}