You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
849 B
39 lines
849 B
5 years ago
|
use chrono::Local;
|
||
|
use colored::Colorize;
|
||
|
|
||
|
use fern::colors::{Color, ColoredLevelConfig};
|
||
|
use fern::Dispatch;
|
||
|
|
||
|
use crate::config::LogLevel;
|
||
|
use crate::result::RudeResult;
|
||
|
|
||
|
/// Initialize the logging facilities. `LevelFilter` must be specified and will
|
||
|
/// determine what level of logs will be shown.`
|
||
|
pub fn init(level: LogLevel) -> RudeResult<()> {
|
||
|
Dispatch::new()
|
||
|
.format(|out, message, record| {
|
||
|
let colors = ColoredLevelConfig::new()
|
||
|
.error(Color::Red)
|
||
|
.warn(Color::Magenta)
|
||
|
.info(Color::Cyan)
|
||
|
.debug(Color::Yellow)
|
||
|
.trace(Color::Green);
|
||
|
|
||
|
out.finish(format_args!(
|
||
|
"{} {} {}",
|
||
|
Local::now()
|
||
|
.format("%Y-%m-%dT%H:%M:%S%.3f%z")
|
||
|
.to_string()
|
||
|
.white()
|
||
|
.bold(),
|
||
|
colors.color(record.level()),
|
||
|
message
|
||
|
))
|
||
|
})
|
||
|
.level(level.level())
|
||
|
.chain(std::io::stdout())
|
||
|
.apply()?;
|
||
|
|
||
|
Ok(())
|
||
|
}
|