use anyhow::Result;
use time::format_description::well_known::Iso8601;
use tracing::{Level, metadata::LevelFilter};
use tracing_subscriber::{
fmt::{self, time::UtcTime},
prelude::__tracing_subscriber_SubscriberExt,
registry,
util::SubscriberInitExt,
};
pub(crate) fn initialize(level: Level) -> Result<()> {
let format = fmt::layer()
.compact()
.with_level(true)
.with_ansi(true)
.with_target(false)
.with_timer(UtcTime::new(Iso8601::DEFAULT))
.with_ansi_sanitization(false);
let filter_layer = LevelFilter::from(level);
Ok(registry().with(format).with(filter_layer).try_init()?)
}
#[cfg(test)]
mod test {
use super::initialize;
use tracing::Level;
#[test]
fn initialize_does_not_panic() {
drop(initialize(Level::INFO));
}
}