pub fn init_subscriber(config: LoggingConfig)Expand description
Initialize logging with the provided configuration
This function takes a LoggingConfig and sets up the global logging infrastructure.
After calling this, all logging macros (tracing::info!, etc.) will use
this configuration.
This is the single source of truth for subscriber initialization. All other init functions delegate to this to eliminate duplication.
Automatically configures ANSI codes:
- File output: ANSI codes disabled (clean text for parsing)
- Stderr output: ANSI codes enabled (colored terminal output)
Note: We cannot extract the format-specific layer creation into a separate function because each format (Pretty, Json, Compact) creates a different concrete type, and Rust’s type system requires all match arms to return the same type. Type erasure with boxed layers would work but adds runtime overhead for a one-time initialization cost.
§Arguments
config- The logging configuration containing all settings
§Panics
Panics if:
- Log directory cannot be created (filesystem permissions issue)
- Subscriber initialization fails (usually means it was already initialized)
Both panics are intentional as logging is critical for observability.
§Example
use std::path::PathBuf;
use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingConfig, init_subscriber};
let config = LoggingConfig::new(
PathBuf::from("./data/logs"),
LogFormat::Compact,
LogFormat::Pretty,
LogOutput::FileAndStderr,
);
init_subscriber(config);