mirror of
https://github.com/astral-sh/ruff
synced 2026-01-22 05:51:03 -05:00
38 lines
903 B
Rust
38 lines
903 B
Rust
use anyhow::Result;
|
|
use fern;
|
|
|
|
#[macro_export]
|
|
macro_rules! tell_user {
|
|
($($arg:tt)*) => {
|
|
println!(
|
|
"[{}] {}",
|
|
chrono::Local::now()
|
|
.format("%H:%M:%S %p")
|
|
.to_string()
|
|
.dimmed(),
|
|
format_args!($($arg)*)
|
|
)
|
|
}
|
|
}
|
|
|
|
pub fn set_up_logging(verbose: bool) -> Result<()> {
|
|
fern::Dispatch::new()
|
|
.format(|out, message, record| {
|
|
out.finish(format_args!(
|
|
"{}[{}][{}] {}",
|
|
chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"),
|
|
record.target(),
|
|
record.level(),
|
|
message
|
|
))
|
|
})
|
|
.level(if verbose {
|
|
log::LevelFilter::Debug
|
|
} else {
|
|
log::LevelFilter::Info
|
|
})
|
|
.chain(std::io::stdout())
|
|
.apply()
|
|
.map_err(|e| e.into())
|
|
}
|