diff --git a/src/tracing.rs b/src/tracing.rs index d3d3558..36c28f2 100644 --- a/src/tracing.rs +++ b/src/tracing.rs @@ -1,17 +1,13 @@ use std::path::Path; -use const_format::formatcp; use tracing::level_filters::LevelFilter; use tracing_appender::non_blocking::WorkerGuard; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::{EnvFilter, Layer}; -const DEFAULT_FILE_DIRECTIVE: &str = formatcp!("info,{}=debug", env!("CARGO_PKG_NAME")); -const LOG_FILE_NAME: &str = formatcp!("{}.log", env!("CARGO_PKG_NAME")); - #[must_use] -pub fn setup_tracing(log_directory: Option<&Path>) -> Option { +pub fn setup_tracing(pkg_name: &str, log_directory: Option<&Path>) -> Option { // Setup stdout layer. let stdout_filter = EnvFilter::builder() .with_env_var("RUST_LOG") @@ -25,12 +21,13 @@ pub fn setup_tracing(log_directory: Option<&Path>) -> Option { // Setup file layer (if requested). let (file_layer, file_guard) = log_directory .map(|directory| { - let file_appender = tracing_appender::rolling::hourly(directory, LOG_FILE_NAME); + let file_appender = + tracing_appender::rolling::hourly(directory, format!("{pkg_name}.log")); let (file_writer, file_guard) = tracing_appender::non_blocking(file_appender); // Load the user's file filter else fallback to the default. let file_filter = std::env::var("RUST_FILE_LOG").ok(); - let file_filter = file_filter.as_deref().unwrap_or(DEFAULT_FILE_DIRECTIVE); + let file_filter = file_filter.unwrap_or_else(|| format!("info,{pkg_name}=debug")); let file_filter: EnvFilter = file_filter.parse().unwrap(); let file_layer = tracing_subscriber::fmt::layer()