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 onlyLogOutput::FileAndStderr- Development/testing: logs to both file and stderr
§Usage
§Builder Pattern (Recommended)
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§
- Logging
Builder - Builder for constructing a tracing subscriber with flexible configuration
- Logging
Config - Configuration for logging system initialization
Enums§
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