From 9d5550bf5fee123f7cdb9da61bbc8bd506957de5 Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Wed, 20 Mar 2024 16:04:55 -0700 Subject: [PATCH] default log level to logger::Level --- bin/core/src/config.rs | 2 +- bin/periphery/src/config.rs | 6 +----- client/rs/src/entities/config.rs | 22 ++++++++++++---------- lib/logger/src/lib.rs | 12 +++++++++++- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/bin/core/src/config.rs b/bin/core/src/config.rs index a76ba0cd0..51f49c9ad 100644 --- a/bin/core/src/config.rs +++ b/bin/core/src/config.rs @@ -31,7 +31,7 @@ fn default_frontend_path() -> String { pub fn core_config() -> &'static CoreConfig { static CORE_CONFIG: OnceLock = OnceLock::new(); CORE_CONFIG.get_or_init(|| { - let env = &env(); + let env = env(); let config_path = &env.config_path; let mut config = parse_config_file::(config_path.as_str()) diff --git a/bin/periphery/src/config.rs b/bin/periphery/src/config.rs index ee3621588..107e6736f 100644 --- a/bin/periphery/src/config.rs +++ b/bin/periphery/src/config.rs @@ -95,7 +95,7 @@ pub struct PeripheryConfig { pub port: u16, /// Configure the logging level: error, warn, info, debug, trace - #[serde(default = "default_log_level")] + #[serde(default)] pub log_level: logger::LogLevel, /// The system directory where monitor managed repos will be cloned @@ -131,10 +131,6 @@ fn default_periphery_port() -> u16 { 8000 } -fn default_log_level() -> logger::LogLevel { - logger::LogLevel::Info -} - fn default_repo_dir() -> PathBuf { "/repos".parse().unwrap() } diff --git a/client/rs/src/entities/config.rs b/client/rs/src/entities/config.rs index d96dd027d..bde09f6b2 100644 --- a/client/rs/src/entities/config.rs +++ b/client/rs/src/entities/config.rs @@ -7,47 +7,49 @@ pub struct CoreConfig { #[serde(default = "default_title")] pub title: String, - // the host to use with oauth redirect url, whatever host the user hits to access monitor. eg 'https://monitor.mogh.tech' + /// The host to use with oauth redirect url, whatever host the user hits to access monitor. eg 'https://monitor.mogh.tech' #[serde(default)] pub host: String, - // port the core web server runs on + /// Port the core web server runs on #[serde(default = "default_core_port")] pub port: u16, - // sent in auth header with req to periphery + /// Sent in auth header with req to periphery pub passkey: String, + /// Configure custom log level: trace | debug | info | warn | error. default: info #[serde(default)] pub log_level: LogLevel, + /// Control how long distributed JWT remain valid for. Default is 1-day #[serde(default = "default_jwt_valid_for")] pub jwt_valid_for: Timelength, - // interval at which to collect server stats and send any alerts + /// interval at which to collect server stats and send any alerts #[serde(default = "default_monitoring_interval")] pub monitoring_interval: Timelength, - // number of days to keep stats, or 0 to disable pruning. stats older than this number of days are deleted on a daily cycle + /// number of days to keep stats, or 0 to disable pruning. stats older than this number of days are deleted on a daily cycle #[serde(default)] pub keep_stats_for_days: u64, - // number of days to keep alerts, or 0 to disable pruning. alerts older than this number of days are deleted on a daily cycle + /// number of days to keep alerts, or 0 to disable pruning. alerts older than this number of days are deleted on a daily cycle #[serde(default)] pub keep_alerts_for_days: u64, - // used to verify validity from github webhooks + /// used to verify validity from github webhooks #[serde(default)] pub github_webhook_secret: String, - // used to form the frontend listener url, if None will use 'host'. + /// used to form the frontend listener url, if None will use 'host'. pub github_webhook_base_url: Option, - // allowed docker orgs used with monitor. first in this list will be default for build + /// allowed docker orgs used with monitor. first in this list will be default for build #[serde(default)] pub docker_organizations: Vec, - // enable login with local auth + /// enable login with local auth #[serde(default)] pub local_auth: bool, diff --git a/lib/logger/src/lib.rs b/lib/logger/src/lib.rs index ff4667584..c6d37384c 100644 --- a/lib/logger/src/lib.rs +++ b/lib/logger/src/lib.rs @@ -9,11 +9,21 @@ pub fn init(log_level: impl Into) { } #[derive( - Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, + Debug, + Clone, + Copy, + Default, + PartialEq, + Eq, + Hash, + Serialize, + Deserialize, )] +#[serde(rename_all = "lowercase")] pub enum LogLevel { Trace, Debug, + #[default] Info, Warn, Error,