master
rascul 5 years ago
parent 1721b243d5
commit d50763aaee

@ -0,0 +1,3 @@
hard_tabs = true
newline_style = "unix"
use_try_shorthand = true

@ -1,19 +1,18 @@
/// Logger implementation for colors in the terminal and in the future
/// logging to a file and to a remote log server
extern crate chrono;
extern crate colored;
extern crate log;
use colored::*;
use log::{Log, LogLevel, LogLevelFilter, LogMetadata, LogRecord, set_logger};
use log::{set_logger, Log, LogLevel, LogLevelFilter, LogMetadata, LogRecord};
pub mod error;
#[cfg(test)]
mod tests;
pub mod error;
pub use error::RagResult;
pub use error::RagError;
pub use error::RagResult;
struct Logger;
@ -28,21 +27,26 @@ impl Log for Logger {
let ts = now.format("%Y-%m-%dT%H:%M:%S%.3f%z").to_string();
let (msg, _level) = match record.level() {
LogLevel::Error => {
(format!("{} {} {}", ts.white().bold(), "ERR".red(), record.args()), 3)
}
LogLevel::Warn => {
(format!("{} {} {}", ts.white().bold(), "WRN".purple(), record.args()), 4)
}
LogLevel::Info => {
(format!("{} {} {}", ts.white().bold(), "INF".cyan(), record.args()), 6)
}
LogLevel::Debug => {
(format!("{} {} {}", ts.white().bold(), "DBG".yellow(), record.args()), 7)
}
LogLevel::Trace => {
(format!("{} {} {}", ts.white().bold(), "TRC".green(), record.args()), 0)
}
LogLevel::Error => (
format!("{} {} {}", ts.white().bold(), "ERR".red(), record.args()),
3,
),
LogLevel::Warn => (
format!("{} {} {}", ts.white().bold(), "WRN".purple(), record.args()),
4,
),
LogLevel::Info => (
format!("{} {} {}", ts.white().bold(), "INF".cyan(), record.args()),
6,
),
LogLevel::Debug => (
format!("{} {} {}", ts.white().bold(), "DBG".yellow(), record.args()),
7,
),
LogLevel::Trace => (
format!("{} {} {}", ts.white().bold(), "TRC".green(), record.args()),
0,
),
};
println!("{}", msg);
}

Loading…
Cancel
Save