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.
36 lines
713 B
36 lines
713 B
use chrono::Local;
|
|
use colored::Colorize;
|
|
use fern::colors::{Color, ColoredLevelConfig};
|
|
use fern::Dispatch;
|
|
|
|
use crate::config::LogLevel;
|
|
use crate::result::Result;
|
|
|
|
pub fn setup(level: &LogLevel) -> Result<()> {
|
|
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(())
|
|
}
|