From 100e90d50174b6446bf0e779ab77c715df5dea5c Mon Sep 17 00:00:00 2001 From: RGBCube Date: Thu, 12 Jun 2025 00:09:37 +0300 Subject: [PATCH] config: add debug logs --- src/config.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index ef2e14d..e474f89 100644 --- a/src/config.rs +++ b/src/config.rs @@ -471,13 +471,22 @@ pub struct DaemonConfig { } impl DaemonConfig { + const DEFAULT: &str = include_str!("../config.toml"); + pub fn load_from(path: Option<&Path>) -> anyhow::Result { let contents = if let Some(path) = path { + log::debug!("loading config from '{path}'", path = path.display()); + &fs::read_to_string(path).with_context(|| { format!("failed to read config from '{path}'", path = path.display()) })? } else { - include_str!("../config.toml") + log::debug!( + "loading default config from embedded toml:\n{config}", + config = Self::DEFAULT, + ); + + Self::DEFAULT }; let mut config: Self = toml::from_str(contents).with_context(|| { @@ -499,6 +508,15 @@ impl DaemonConfig { } } + // This is just for debug traces. + if log::max_level() >= log::LevelFilter::Debug { + if config.rules.is_sorted_by_key(|rule| rule.priority) { + log::debug!("config rules are sorted by increasing priority, not doing anything"); + } else { + log::debug!("config rules aren't sorted by priority, sorting"); + } + } + config.rules.sort_by_key(|rule| rule.priority); log::debug!("loaded config: {config:#?}");