modbus_relay/config/
logging.rs

1use serde::{Deserialize, Serialize};
2use tracing::level_filters::LevelFilter;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5#[serde(deny_unknown_fields)]
6pub struct Config {
7    /// Directory to store log files
8    pub log_dir: String,
9
10    /// Enable trace-level logging for frame contents
11    pub trace_frames: bool,
12
13    /// Minimum log level for console output
14    pub level: String,
15
16    /// Log format (pretty or json)
17    pub format: String,
18
19    /// Whether to include source code location in logs
20    pub include_location: bool,
21
22    /// Whether to include thread IDs in logs
23    pub thread_ids: bool,
24
25    /// Whether to include thread names in logs
26    pub thread_names: bool,
27}
28
29impl Default for Config {
30    fn default() -> Self {
31        Self {
32            log_dir: "logs".to_string(),
33            trace_frames: false,
34            level: "info".to_string(),
35            format: "pretty".to_string(),
36            include_location: false,
37            thread_ids: false,
38            thread_names: false,
39        }
40    }
41}
42
43impl Config {
44    pub fn get_level_filter(&self) -> LevelFilter {
45        match self.level.to_lowercase().as_str() {
46            "error" => LevelFilter::ERROR,
47            "warn" => LevelFilter::WARN,
48            "info" => LevelFilter::INFO,
49            "debug" => LevelFilter::DEBUG,
50            "trace" => LevelFilter::TRACE,
51            _ => LevelFilter::INFO, // Fallback to INFO if invalid
52        }
53    }
54}