-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathlog.rs
More file actions
83 lines (71 loc) · 2.13 KB
/
Copy pathlog.rs
File metadata and controls
83 lines (71 loc) · 2.13 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
use std::path::PathBuf;
use eyre::Result;
use serde::{Deserialize, Serialize};
use super::{load_optional_env_var, CommitBoostConfig, LOGS_DIR_DEFAULT, LOGS_DIR_ENV};
use crate::utils::default_bool;
#[derive(Clone, Default, Debug, Deserialize, Serialize)]
pub struct LogsSettings {
/// Whether to export OpenTelemetry traces
#[serde(default = "default_bool::<false>")]
pub export_traces: bool,
#[serde(default)]
pub stdout: StdoutLogSettings,
#[serde(default)]
pub file: FileLogSettings,
}
impl LogsSettings {
pub fn from_env_config() -> Result<Self> {
let mut config = CommitBoostConfig::from_env_path()?;
// Override log dir path if env var is set
if let Some(log_dir) = load_optional_env_var(LOGS_DIR_ENV) {
config.logs.file.dir_path = log_dir.into();
}
Ok(config.logs)
}
}
fn default_log_dir_path() -> PathBuf {
LOGS_DIR_DEFAULT.into()
}
fn default_level() -> String {
"info".into()
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct StdoutLogSettings {
#[serde(default = "default_bool::<true>")]
pub enabled: bool,
#[serde(default = "default_level")]
pub level: String,
#[serde(default = "default_bool::<false>")]
pub use_json: bool,
#[serde(default = "default_bool::<true>")]
pub color: bool,
}
impl Default for StdoutLogSettings {
fn default() -> Self {
Self { enabled: true, level: "info".into(), use_json: false, color: true }
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct FileLogSettings {
#[serde(default = "default_bool::<false>")]
pub enabled: bool,
#[serde(default = "default_level")]
pub level: String,
#[serde(default = "default_bool::<true>")]
pub use_json: bool,
#[serde(default = "default_log_dir_path")]
pub dir_path: PathBuf,
#[serde(default)]
pub max_files: Option<usize>,
}
impl Default for FileLogSettings {
fn default() -> Self {
Self {
enabled: false,
level: "info".into(),
use_json: true,
dir_path: default_log_dir_path(),
max_files: None,
}
}
}