Skip to main content

backbone_core/config/
logging_config.rs

1//! Logging configuration
2//!
3//! Defines logging settings including levels, formats, and file output.
4
5use serde::{Deserialize, Serialize};
6
7/// Logging configuration
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct LoggingConfig {
10    /// Log level (trace, debug, info, warn, error)
11    #[serde(default = "default_log_level")]
12    pub level: String,
13    /// Use structured logging
14    #[serde(default = "default_true")]
15    pub structured: bool,
16    /// Log format (json, pretty, compact)
17    #[serde(default = "default_log_format")]
18    pub format: String,
19    /// Log targets
20    #[serde(default = "default_log_targets")]
21    pub targets: Vec<String>,
22    /// File logging configuration
23    #[serde(default)]
24    pub file: Option<LoggingFileConfig>,
25}
26
27fn default_true() -> bool { true }
28fn default_log_level() -> String { "info".to_string() }
29fn default_log_format() -> String { "json".to_string() }
30fn default_log_targets() -> Vec<String> { vec!["console".to_string()] }
31
32impl Default for LoggingConfig {
33    fn default() -> Self {
34        Self {
35            level: default_log_level(),
36            structured: true,
37            format: default_log_format(),
38            targets: default_log_targets(),
39            file: None,
40        }
41    }
42}
43
44/// File logging configuration
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct LoggingFileConfig {
47    /// Log file path
48    pub path: String,
49    /// Max file size (e.g., "100MB")
50    #[serde(default)]
51    pub max_size: Option<String>,
52    /// Max number of files to keep
53    #[serde(default)]
54    pub max_files: Option<u32>,
55    /// Compress rotated files
56    #[serde(default)]
57    pub compress: Option<bool>,
58}