pub fn init_with_format(log_dir: &Path, output: LogOutput, format: &LogFormat)Expand description
Initialize logging based on the chosen format and output target
This is a convenience wrapper around LoggingBuilder for backward compatibility.
Consider using LoggingBuilder directly for more flexibility.
This function applies the same format to both file and stderr outputs.
For independent format control, use LoggingBuilder with with_file_format()
and with_stderr_format().
§Arguments
log_dir- Directory where log files should be written (e.g.,./data/logsfor production)output- Where to write logs (file only or file + stderr)format- The logging format to use for both outputs
§Panics
Panics if log file cannot be created or log directory cannot be created. This is intentional as logging is critical for observability.
§Example
use std::path::Path;
use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, init_with_format};
// Initialize with JSON format for E2E tests with production location
init_with_format(Path::new("./data/logs"), LogOutput::FileAndStderr, &LogFormat::Json);
// Initialize with compact format for production
init_with_format(Path::new("./data/logs"), LogOutput::FileOnly, &LogFormat::Compact);
// Initialize for testing with isolated directory
init_with_format(Path::new("/tmp/test-xyz/data/logs"), LogOutput::FileAndStderr, &LogFormat::Pretty);