sermo/src/logging.rs
user0-07161 0489cac646
All checks were successful
build / test-alpine (push) Successful in 50s
build / test-debian (push) Successful in 1m19s
feat: rework logging and tracing
2026-02-15 16:49:11 +01:00

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()),
}
}
}