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

Loading…
Cancel
Save