Skip to main content

Module logging

Module logging 

Source
Expand description

Simplified Structured Logging Configuration

Provides basic logging configuration with tracing spans for the three-level architecture:

  • Commands (Level 1): Top-level orchestration
  • Steps (Level 2): Mid-level execution units
  • Remote Actions (Level 3): Leaf-level operations

§Persistent Logging

All logs are always written to a log file for persistent storage. This enables post-mortem analysis and troubleshooting of production deployments.

By default, logs are written to ./data/logs/log.txt in production environments. For testing, a different log directory can be specified to avoid polluting production data.

§Optional Stderr Output

Logs can optionally be written to stderr for real-time visibility during development and testing. This is controlled by the LogOutput parameter:

  • LogOutput::FileOnly - Production mode: logs to file only
  • LogOutput::FileAndStderr - Development/testing: logs to both file and stderr

§Usage

use std::path::Path;
use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, LogFormat, LoggingBuilder};

// Flexible builder API
LoggingBuilder::new(Path::new("./data/logs"))
    .with_format(LogFormat::Compact)
    .with_output(LogOutput::FileAndStderr)
    .init();

§Convenience Functions

use std::path::Path;
use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, init_compact};

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

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

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

Structs§

LoggingBuilder
Builder for constructing a tracing subscriber with flexible configuration
LoggingConfig
Configuration for logging system initialization

Enums§

LogFormat
Logging format options for different environments
LogOutput
Output target for logging

Constants§

LOG_FILE_NAME
Log file name used by the logging system

Functions§

init
Initialize the tracing subscriber with default pretty formatting
init_compact
Initialize the tracing subscriber with compact formatting
init_json
Initialize the tracing subscriber with JSON formatting
init_subscriber
Initialize logging with the provided configuration
init_with_format
Initialize logging based on the chosen format and output target