Skip to content

Commit 9ae6359

Browse files
Copilotjosecelano
andcommitted
docs: [#3] add comprehensive logging documentation for users and contributors
Co-authored-by: josecelano <[email protected]>
1 parent cc20e2d commit 9ae6359

File tree

5 files changed

+512
-0
lines changed

5 files changed

+512
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,44 @@ cargo install --path .
107107
torrust-tracker-deployer
108108
```
109109

110+
#### 📊 Logging Configuration
111+
112+
The application includes comprehensive logging for observability and troubleshooting:
113+
114+
```bash
115+
# Default behavior (production) - logs to file only in compact format
116+
torrust-tracker-deployer
117+
118+
# Development mode - show logs on stderr in real-time
119+
torrust-tracker-deployer --log-output file-and-stderr
120+
121+
# Use pretty format for readability during development
122+
torrust-tracker-deployer --log-format pretty --log-output file-and-stderr
123+
124+
# JSON format for production monitoring and log aggregation
125+
torrust-tracker-deployer --log-format json
126+
127+
# Custom log directory
128+
torrust-tracker-deployer --log-dir /var/log/deployer
129+
130+
# Control log level with RUST_LOG environment variable
131+
RUST_LOG=debug torrust-tracker-deployer --log-output file-and-stderr
132+
RUST_LOG=trace torrust-tracker-deployer --log-output file-and-stderr
133+
```
134+
135+
**Log Format Options:**
136+
137+
- `compact` (default) - Space-efficient, readable format for production
138+
- `pretty` - Detailed, formatted output for development
139+
- `json` - Machine-readable format for log aggregation systems
140+
141+
**Log Output Modes:**
142+
143+
- `file-only` (default) - Write logs to `./data/logs/log.txt` only (production mode)
144+
- `file-and-stderr` - Write logs to both file and stderr (development/testing mode)
145+
146+
**[📖 See detailed logging documentation →](docs/user-guide/logging.md)**
147+
110148
#### 🔧 Development Tasks
111149

112150
This project includes convenient scripts for common development tasks:

custom-logs/log.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2025-10-15T12:42:14.572174Z  INFO torrust_tracker_deployer::app: Application started app="torrust-tracker-deployer" version="0.1.0" log_dir=./custom-logs log_format=Compact log_output=FileAndStderr
2+
2025-10-15T12:42:14.572262Z  INFO torrust_tracker_deployer::app: Application finished

docs/contributing/logging-guide.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,63 @@
22

33
This guide explains the structured logging implementation in the Torrust Tracker Deployer project, which uses hierarchical structured logging.
44

5+
## Main Application Logging
6+
7+
The main CLI application (`src/main.rs``src/app.rs`) initializes logging at startup with user-configurable options. This provides a consistent logging infrastructure for all operations.
8+
9+
### Application Logging Setup
10+
11+
The main application uses `LoggingBuilder` with CLI arguments for configuration:
12+
13+
```rust
14+
// src/app.rs
15+
use torrust_tracker_deployer_lib::logging::{LogFormat, LogOutput, LoggingBuilder};
16+
17+
pub fn run() {
18+
let cli = Cli::parse();
19+
20+
// Initialize logging FIRST before any other logic
21+
LoggingBuilder::new(&cli.log_dir)
22+
.with_format(cli.log_format)
23+
.with_output(cli.log_output)
24+
.init();
25+
26+
// Log startup with context
27+
info!(
28+
app = "torrust-tracker-deployer",
29+
version = env!("CARGO_PKG_VERSION"),
30+
log_dir = %cli.log_dir.display(),
31+
log_format = ?cli.log_format,
32+
log_output = ?cli.log_output,
33+
"Application started"
34+
);
35+
36+
// ... application logic ...
37+
38+
info!("Application finished");
39+
}
40+
```
41+
42+
### User-Facing Configuration
43+
44+
Users can configure logging via CLI arguments:
45+
46+
```bash
47+
# Default (production): file-only, compact format
48+
torrust-tracker-deployer
49+
50+
# Development: stderr output, pretty format
51+
torrust-tracker-deployer --log-format pretty --log-output file-and-stderr
52+
53+
# Custom log directory
54+
torrust-tracker-deployer --log-dir /var/log/deployer
55+
56+
# JSON format for log aggregation
57+
torrust-tracker-deployer --log-format json
58+
```
59+
60+
See [User Guide: Logging](../user-guide/logging.md) for complete user documentation.
61+
562
## JSON Output Format
663

764
When using `logging::init_json()` or `LogFormat::Json`, logs are output in JSON format suitable for log aggregation:

0 commit comments

Comments
 (0)