-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlogging.rs
More file actions
735 lines (703 loc) · 26.6 KB
/
logging.rs
File metadata and controls
735 lines (703 loc) · 26.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
//! 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
//!
//! ### Builder Pattern (Recommended)
//!
//! ```rust,no_run
//! 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
//!
//! ```rust,no_run
//! 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);
//! ```
use std::io;
use std::path::Path;
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
/// Log file name used by the logging system
pub const LOG_FILE_NAME: &str = "log.txt";
/// Output target for logging
#[derive(Clone, Copy, Debug, clap::ValueEnum)]
pub enum LogOutput {
/// Write logs to file only (production mode)
FileOnly,
/// Write logs to both file and stderr (development/testing mode)
FileAndStderr,
}
/// Logging format options for different environments
#[derive(Clone, Debug, clap::ValueEnum)]
pub enum LogFormat {
/// Pretty-printed console output for development (default)
Pretty,
/// JSON output for production environments
Json,
/// Compact console output for minimal verbosity
Compact,
}
// ============================================================================
// LOGGING CONFIGURATION - Domain Type
// ============================================================================
/// Configuration for logging system initialization
///
/// This struct represents the domain-specific logging configuration that is
/// independent of CLI parsing concerns. It can be constructed from CLI arguments
/// or other configuration sources without creating circular dependencies.
///
/// # Design Principles
///
/// - **Independence**: No dependency on presentation layer types
/// - **Reusability**: Can be constructed from various sources (CLI, config files, tests)
/// - **Clarity**: Clear field names and comprehensive documentation
#[derive(Debug, Clone)]
pub struct LoggingConfig {
/// Directory where log files will be written
pub log_dir: std::path::PathBuf,
/// Format for file logging output
pub file_format: LogFormat,
/// Format for stderr logging output
pub stderr_format: LogFormat,
/// Output target (file-only vs file-and-stderr)
pub output: LogOutput,
}
impl LoggingConfig {
/// Create a new logging configuration
///
/// # Arguments
///
/// * `log_dir` - Directory for log files
/// * `file_format` - Format for file output
/// * `stderr_format` - Format for stderr output
/// * `output` - Output target configuration
#[must_use]
pub fn new(
log_dir: std::path::PathBuf,
file_format: LogFormat,
stderr_format: LogFormat,
output: LogOutput,
) -> Self {
Self {
log_dir,
file_format,
stderr_format,
output,
}
}
}
// ============================================================================
// BUILDER PATTERN - Core Implementation
// ============================================================================
/// Builder for constructing a tracing subscriber with flexible configuration
///
/// This builder provides a fluent API for configuring logging with different
/// formats and output targets. It eliminates code duplication by centralizing
/// layer creation and subscriber initialization.
///
/// Supports independent format control for file and stderr outputs, with
/// automatic ANSI code handling (disabled for files, enabled for stderr).
///
/// # Examples
///
/// ```rust,no_run
/// use std::path::Path;
/// use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, LogFormat, LoggingBuilder};
///
/// // Basic usage with defaults (Compact file format, Pretty stderr format, FileAndStderr output)
/// LoggingBuilder::new(Path::new("./data/logs")).init();
///
/// // Custom configuration with independent formats
/// LoggingBuilder::new(Path::new("./data/logs"))
/// .with_file_format(LogFormat::Json)
/// .with_stderr_format(LogFormat::Pretty)
/// .with_output(LogOutput::FileAndStderr)
/// .init();
///
/// // Backward compatible with single format for both outputs
/// LoggingBuilder::new(Path::new("./data/logs"))
/// .with_format(LogFormat::Compact)
/// .with_output(LogOutput::FileOnly)
/// .init();
/// ```
pub struct LoggingBuilder {
log_dir: std::path::PathBuf,
file_format: LogFormat,
stderr_format: LogFormat,
output: LogOutput,
}
impl LoggingBuilder {
/// Create a new logging builder with default settings
///
/// Default configuration:
/// - File Format: `LogFormat::Compact` (no ANSI codes)
/// - Stderr Format: `LogFormat::Pretty` (with ANSI codes)
/// - Output: `LogOutput::FileAndStderr`
///
/// # Arguments
///
/// * `log_dir` - Directory where log files should be written (e.g., `./data/logs`)
#[must_use]
pub fn new(log_dir: &Path) -> Self {
Self {
log_dir: log_dir.to_path_buf(),
file_format: LogFormat::Compact,
stderr_format: LogFormat::Pretty,
output: LogOutput::FileAndStderr,
}
}
/// Set the logging format for both file and stderr outputs
///
/// This is a convenience method for backward compatibility.
/// For independent format control, use `with_file_format()` and `with_stderr_format()`.
///
/// # Arguments
///
/// * `format` - The desired logging format (Pretty, Json, or Compact)
#[must_use]
pub fn with_format(mut self, format: LogFormat) -> Self {
self.file_format = format.clone();
self.stderr_format = format;
self
}
/// Set the logging format for file output
///
/// ANSI codes are automatically disabled for file output to ensure
/// logs are easily parsed with standard text tools (grep, awk, sed).
///
/// # Arguments
///
/// * `format` - The desired logging format for files (Pretty, Json, or Compact)
#[must_use]
pub fn with_file_format(mut self, format: LogFormat) -> Self {
self.file_format = format;
self
}
/// Set the logging format for stderr output
///
/// ANSI codes are automatically enabled for stderr output to provide
/// colored terminal output for better readability.
///
/// # Arguments
///
/// * `format` - The desired logging format for stderr (Pretty, Json, or Compact)
#[must_use]
pub fn with_stderr_format(mut self, format: LogFormat) -> Self {
self.stderr_format = format;
self
}
/// Set the output target
///
/// # Arguments
///
/// * `output` - Where to write logs (`FileOnly` or `FileAndStderr`)
#[must_use]
pub fn with_output(mut self, output: LogOutput) -> Self {
self.output = output;
self
}
/// Initialize the global tracing subscriber with the configured settings
///
/// This consumes the builder and sets up the global logging infrastructure.
/// After calling this, all logging macros (`tracing::info!`, etc.) will use
/// this configuration.
///
/// # Panics
///
/// Panics if:
/// - Log directory cannot be created (filesystem permissions issue)
/// - Subscriber initialization fails (usually means it was already initialized)
///
/// Both panics are intentional as logging is critical for observability.
pub fn init(self) {
let config = LoggingConfig::new(
self.log_dir,
self.file_format,
self.stderr_format,
self.output,
);
init_subscriber(config);
}
}
// ============================================================================
// PUBLIC INITIALIZATION FUNCTIONS
// ============================================================================
/// Initialize logging with the provided configuration
///
/// This function takes a `LoggingConfig` and sets up the global logging infrastructure.
/// After calling this, all logging macros (`tracing::info!`, etc.) will use
/// this configuration.
///
/// This is the single source of truth for subscriber initialization.
/// All other init functions delegate to this to eliminate duplication.
///
/// Automatically configures ANSI codes:
/// - File output: ANSI codes disabled (clean text for parsing)
/// - Stderr output: ANSI codes enabled (colored terminal output)
///
/// Note: We cannot extract the format-specific layer creation into a separate
/// function because each format (Pretty, Json, Compact) creates a different
/// concrete type, and Rust's type system requires all match arms to return
/// the same type. Type erasure with boxed layers would work but adds runtime
/// overhead for a one-time initialization cost.
///
/// # Arguments
///
/// * `config` - The logging configuration containing all settings
///
/// # Panics
///
/// Panics if:
/// - Log directory cannot be created (filesystem permissions issue)
/// - Subscriber initialization fails (usually means it was already initialized)
///
/// Both panics are intentional as logging is critical for observability.
///
/// # Example
///
/// ```rust,no_run
/// use std::path::PathBuf;
/// use torrust_tracker_deployer_lib::bootstrap::logging::{LogFormat, LogOutput, LoggingConfig, init_subscriber};
///
/// let config = LoggingConfig::new(
/// PathBuf::from("./data/logs"),
/// LogFormat::Compact,
/// LogFormat::Pretty,
/// LogOutput::FileAndStderr,
/// );
///
/// init_subscriber(config);
/// ```
#[allow(clippy::too_many_lines)]
pub fn init_subscriber(config: LoggingConfig) {
let file_appender = create_log_file_appender(&config.log_dir);
let env_filter = create_env_filter();
match config.output {
LogOutput::FileOnly => {
// File-only mode: single layer with ANSI disabled
match config.file_format {
LogFormat::Pretty => {
tracing_subscriber::registry()
.with(
fmt::layer()
.pretty()
.with_ansi(false)
.with_writer(file_appender),
)
.with(env_filter)
.init();
}
LogFormat::Json => {
tracing_subscriber::registry()
.with(
fmt::layer()
.json()
.with_ansi(false)
.with_writer(file_appender),
)
.with(env_filter)
.init();
}
LogFormat::Compact => {
tracing_subscriber::registry()
.with(
fmt::layer()
.compact()
.with_ansi(false)
.with_writer(file_appender),
)
.with(env_filter)
.init();
}
}
}
LogOutput::FileAndStderr => {
// Dual output mode: file layer (no ANSI) + stderr layer (with ANSI)
match (config.file_format, config.stderr_format) {
// Pretty file format combinations
(LogFormat::Pretty, LogFormat::Pretty) => {
tracing_subscriber::registry()
.with(
fmt::layer()
.pretty()
.with_ansi(false)
.with_writer(file_appender),
)
.with(
fmt::layer()
.pretty()
.with_ansi(true)
.with_writer(io::stderr),
)
.with(env_filter)
.init();
}
(LogFormat::Pretty, LogFormat::Json) => {
tracing_subscriber::registry()
.with(
fmt::layer()
.pretty()
.with_ansi(false)
.with_writer(file_appender),
)
.with(fmt::layer().json().with_ansi(true).with_writer(io::stderr))
.with(env_filter)
.init();
}
(LogFormat::Pretty, LogFormat::Compact) => {
tracing_subscriber::registry()
.with(
fmt::layer()
.pretty()
.with_ansi(false)
.with_writer(file_appender),
)
.with(
fmt::layer()
.compact()
.with_ansi(true)
.with_writer(io::stderr),
)
.with(env_filter)
.init();
}
// JSON file format combinations
(LogFormat::Json, LogFormat::Pretty) => {
tracing_subscriber::registry()
.with(
fmt::layer()
.json()
.with_ansi(false)
.with_writer(file_appender),
)
.with(
fmt::layer()
.pretty()
.with_ansi(true)
.with_writer(io::stderr),
)
.with(env_filter)
.init();
}
(LogFormat::Json, LogFormat::Json) => {
tracing_subscriber::registry()
.with(
fmt::layer()
.json()
.with_ansi(false)
.with_writer(file_appender),
)
.with(fmt::layer().json().with_ansi(true).with_writer(io::stderr))
.with(env_filter)
.init();
}
(LogFormat::Json, LogFormat::Compact) => {
tracing_subscriber::registry()
.with(
fmt::layer()
.json()
.with_ansi(false)
.with_writer(file_appender),
)
.with(
fmt::layer()
.compact()
.with_ansi(true)
.with_writer(io::stderr),
)
.with(env_filter)
.init();
}
// Compact file format combinations
(LogFormat::Compact, LogFormat::Pretty) => {
tracing_subscriber::registry()
.with(
fmt::layer()
.compact()
.with_ansi(false)
.with_writer(file_appender),
)
.with(
fmt::layer()
.pretty()
.with_ansi(true)
.with_writer(io::stderr),
)
.with(env_filter)
.init();
}
(LogFormat::Compact, LogFormat::Json) => {
tracing_subscriber::registry()
.with(
fmt::layer()
.compact()
.with_ansi(false)
.with_writer(file_appender),
)
.with(fmt::layer().json().with_ansi(true).with_writer(io::stderr))
.with(env_filter)
.init();
}
(LogFormat::Compact, LogFormat::Compact) => {
tracing_subscriber::registry()
.with(
fmt::layer()
.compact()
.with_ansi(false)
.with_writer(file_appender),
)
.with(
fmt::layer()
.compact()
.with_ansi(true)
.with_writer(io::stderr),
)
.with(env_filter)
.init();
}
}
}
}
}
/// Create the environment filter from `RUST_LOG` or default to "info"
///
/// This reads the `RUST_LOG` environment variable to determine the log level.
/// If not set, defaults to "info" level logging.
fn create_env_filter() -> EnvFilter {
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"))
}
/// Create the log file appender that writes to `{log_dir}/log.txt`
///
/// This function creates the log directory if it doesn't exist and returns
/// a non-blocking file appender that will append to the log file.
///
/// # Arguments
///
/// * `log_dir` - Directory where log files should be written (e.g., `./data/logs` for production)
///
/// # Panics
///
/// Panics if the log directory cannot be created. This is intentional as
/// logging is critical for observability.
fn create_log_file_appender(log_dir: &Path) -> tracing_appender::non_blocking::NonBlocking {
// Create directory if it doesn't exist
std::fs::create_dir_all(log_dir).unwrap_or_else(|_| {
panic!(
"Failed to create log directory: {} - check filesystem permissions",
log_dir.display()
)
});
// Create file appender (appends to existing file)
let file_appender = tracing_appender::rolling::never(log_dir, LOG_FILE_NAME);
// Use non-blocking writer for better performance
let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
// Note: We intentionally leak the guard to keep the file open for the application lifetime
std::mem::forget(guard);
non_blocking
}
// ============================================================================
// CONVENIENCE FUNCTIONS - Thin Wrappers for Backward Compatibility
// ============================================================================
/// Initialize the tracing subscriber with default pretty 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
/// - Pretty-printed format for development
/// - Environment-based filtering via `RUST_LOG`
/// - Support for hierarchical spans across three levels
///
/// # 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
/// ```rust,no_run
/// use std::path::Path;
/// use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, init};
///
/// // E2E tests - enable stderr visibility with production location
/// init(Path::new("./data/logs"), LogOutput::FileAndStderr);
///
/// // Production - file only
/// init(Path::new("./data/logs"), LogOutput::FileOnly);
///
/// // Testing - isolated temp directory
/// init(Path::new("/tmp/test-xyz/data/logs"), LogOutput::FileAndStderr);
/// ```
pub fn init(log_dir: &Path, output: LogOutput) {
LoggingBuilder::new(log_dir)
.with_format(LogFormat::Pretty)
.with_output(output)
.init();
}
/// Initialize the tracing subscriber with JSON 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
/// - JSON output format for production environments
/// - Environment-based filtering via `RUST_LOG`
/// - Machine-readable log format for monitoring systems
///
/// # 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
/// ```rust,no_run
/// use std::path::Path;
/// use torrust_tracker_deployer_lib::bootstrap::logging::{LogOutput, init_json};
///
/// // E2E tests - enable stderr visibility with production location
/// init_json(Path::new("./data/logs"), LogOutput::FileAndStderr);
///
/// // Production - file only
/// init_json(Path::new("./data/logs"), LogOutput::FileOnly);
///
/// // Testing - isolated temp directory
/// init_json(Path::new("/tmp/test-xyz/data/logs"), LogOutput::FileAndStderr);
/// ```
pub fn init_json(log_dir: &Path, output: LogOutput) {
LoggingBuilder::new(log_dir)
.with_format(LogFormat::Json)
.with_output(output)
.init();
}
/// 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
/// ```rust,no_run
/// 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);
/// ```
pub fn init_compact(log_dir: &Path, output: LogOutput) {
LoggingBuilder::new(log_dir)
.with_format(LogFormat::Compact)
.with_output(output)
.init();
}
/// 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/logs` for 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
/// ```rust,no_run
/// 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);
/// ```
pub fn init_with_format(log_dir: &Path, output: LogOutput, format: &LogFormat) {
LoggingBuilder::new(log_dir)
.with_format(format.clone())
.with_output(output)
.init();
}