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")]
19#[non_exhaustive]
20pub enum LogRotation {
21    #[default]
22    Daily,
23    Hourly,
24    Never,
25}
26
27/// Configuration for file-based logging.
28#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
29#[serde(default)]
30pub struct LoggingConfig {
31    /// Path to the log file. Empty string disables file logging.
32    #[serde(default = "default_log_file")]
33    pub file: String,
34    /// Log level for the file sink (does not affect stderr/`RUST_LOG`).
35    #[serde(default = "default_log_level")]
36    pub level: String,
37    /// Rotation strategy: daily, hourly, or never.
38    pub rotation: LogRotation,
39    /// Maximum number of rotated log files to retain.
40    #[serde(default = "default_log_max_files")]
41    pub max_files: usize,
42}
43
44impl Default for LoggingConfig {
45    fn default() -> Self {
46        Self {
47            file: default_log_file(),
48            level: default_log_level(),
49            rotation: LogRotation::default(),
50            max_files: default_log_max_files(),
51        }
52    }
53}