Skip to main content

zeph_config/
logging.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4use serde::{Deserialize, Serialize};
5
6use crate::defaults::default_log_file;
7
8fn default_log_level() -> String {
9    "info".to_owned()
10}
11
12fn default_log_max_files() -> usize {
13    7
14}
15
16/// Log file rotation strategy.
17#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Deserialize, Serialize)]
18#[serde(rename_all = "lowercase")]
19pub enum LogRotation {
20    #[default]
21    Daily,
22    Hourly,
23    Never,
24}
25
26/// Configuration for file-based logging.
27#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
28#[serde(default)]
29pub struct LoggingConfig {
30    /// Path to the log file. Empty string disables file logging.
31    #[serde(default = "default_log_file")]
32    pub file: String,
33    /// Log level for the file sink (does not affect stderr/`RUST_LOG`).
34    #[serde(default = "default_log_level")]
35    pub level: String,
36    /// Rotation strategy: daily, hourly, or never.
37    pub rotation: LogRotation,
38    /// Maximum number of rotated log files to retain.
39    #[serde(default = "default_log_max_files")]
40    pub max_files: usize,
41}
42
43impl Default for LoggingConfig {
44    fn default() -> Self {
45        Self {
46            file: default_log_file(),
47            level: default_log_level(),
48            rotation: LogRotation::default(),
49            max_files: default_log_max_files(),
50        }
51    }
52}