mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-27 17:07:44 +00:00
config: add debug logs
This commit is contained in:
parent
c50f5c8812
commit
100e90d501
1 changed files with 19 additions and 1 deletions
|
@ -471,13 +471,22 @@ pub struct DaemonConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DaemonConfig {
|
impl DaemonConfig {
|
||||||
|
const DEFAULT: &str = include_str!("../config.toml");
|
||||||
|
|
||||||
pub fn load_from(path: Option<&Path>) -> anyhow::Result<Self> {
|
pub fn load_from(path: Option<&Path>) -> anyhow::Result<Self> {
|
||||||
let contents = if let Some(path) = path {
|
let contents = if let Some(path) = path {
|
||||||
|
log::debug!("loading config from '{path}'", path = path.display());
|
||||||
|
|
||||||
&fs::read_to_string(path).with_context(|| {
|
&fs::read_to_string(path).with_context(|| {
|
||||||
format!("failed to read config from '{path}'", path = path.display())
|
format!("failed to read config from '{path}'", path = path.display())
|
||||||
})?
|
})?
|
||||||
} else {
|
} 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(|| {
|
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);
|
config.rules.sort_by_key(|rule| rule.priority);
|
||||||
|
|
||||||
log::debug!("loaded config: {config:#?}");
|
log::debug!("loaded config: {config:#?}");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue