Skip to main content

init_compact

Function init_compact 

Source
pub fn init_compact(log_dir: &Path, output: LogOutput)
Expand description

Initialize the tracing subscriber with compact formatting

This is a convenience wrapper around LoggingBuilder for backward compatibility. Consider using LoggingBuilder directly for more flexibility.

Sets up structured logging with:

  • File output to {log_dir}/log.txt (always enabled)
  • Optional stderr output based on output parameter
  • Compact console output for minimal verbosity
  • Environment-based filtering via RUST_LOG
  • Space-efficient format for development

§Arguments

  • log_dir - Directory where log files should be written (e.g., ./data/logs for production)
  • output - Where to write logs (file only or file + stderr)

§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::{LogOutput, init_compact};

// E2E tests - enable stderr visibility with production location
init_compact(Path::new("./data/logs"), LogOutput::FileAndStderr);

// Production - file only
init_compact(Path::new("./data/logs"), LogOutput::FileOnly);

// Testing - isolated temp directory
init_compact(Path::new("/tmp/test-xyz/data/logs"), LogOutput::FileAndStderr);