45 lines
1.1 KiB
Rust
45 lines
1.1 KiB
Rust
use std::str::FromStr;
|
|
|
|
use anyhow::Result;
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub enum LogLevel {
|
|
Debug,
|
|
Default,
|
|
Quiet,
|
|
}
|
|
|
|
impl LogLevel {
|
|
pub fn init_tracing_subscriber(&self) -> Result<()> {
|
|
tracing_subscriber::fmt()
|
|
.with_max_level({
|
|
match self {
|
|
LogLevel::Debug => tracing::Level::DEBUG,
|
|
LogLevel::Default => tracing::Level::INFO,
|
|
LogLevel::Quiet => tracing::Level::ERROR,
|
|
}
|
|
})
|
|
.pretty()
|
|
.with_ansi(true)
|
|
.with_line_number(false)
|
|
.with_file(false)
|
|
.with_thread_ids(false)
|
|
.with_target(false)
|
|
.init();
|
|
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
impl FromStr for LogLevel {
|
|
type Err = String;
|
|
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
|
match s {
|
|
"debug" | "Debug" => Ok(Self::Debug),
|
|
"default" | "Default" => Ok(Self::Default),
|
|
"quiet" | "Quiet" => Ok(Self::Quiet),
|
|
|
|
_ => Err(s.to_string()),
|
|
}
|
|
}
|
|
}
|