feat: allow setting misc.log_filters in config.toml (#552)

Allow setting `log_filters` in `config.toml`

This allows setting a list of `log_filters` in the `[misc]` section in
the `config.toml`. These filters are prepended to any filters listed
with `--log-filters`. Finally, `--verbose` can now be used with
`--log-filters`, and it will append `debug` to the list of filters
rather than replacing it entirely.
This commit is contained in:
Rebecca Turner
2023-09-17 03:04:46 -04:00
committed by GitHub
parent 06a6b7a2eb
commit c1c9fe22df
3 changed files with 21 additions and 10 deletions

View File

@@ -60,6 +60,11 @@
# Extra Home Manager arguments # Extra Home Manager arguments
#home_manager_arguments = ["--flake", "file"] #home_manager_arguments = ["--flake", "file"]
# Extra tracing filter directives
# These are prepended to the `--log-filter` argument
# See: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives
#log_filters = ["topgrade::command=debug", "warn"]
# Commands to run before anything # Commands to run before anything
[pre_commands] [pre_commands]
#"Emacs Snapshot" = "rm -rf ~/.emacs.d/elpa.bak && cp -rl ~/.emacs.d/elpa ~/.emacs.d/elpa.bak" #"Emacs Snapshot" = "rm -rf ~/.emacs.d/elpa.bak && cp -rl ~/.emacs.d/elpa ~/.emacs.d/elpa.bak"

View File

@@ -436,6 +436,8 @@ pub struct Misc {
only: Option<Vec<Step>>, only: Option<Vec<Step>>,
no_self_update: Option<bool>, no_self_update: Option<bool>,
log_filters: Option<Vec<String>>,
} }
#[derive(Deserialize, Default, Debug, Merge)] #[derive(Deserialize, Default, Debug, Merge)]
@@ -832,14 +834,6 @@ impl CommandLineArgs {
pub fn env_variables(&self) -> &Vec<String> { pub fn env_variables(&self) -> &Vec<String> {
&self.env &self.env
} }
pub fn tracing_filter_directives(&self) -> String {
if self.verbose {
"debug".into()
} else {
self.log_filter.clone()
}
}
} }
/// Represents the application configuration /// Represents the application configuration
@@ -1390,6 +1384,19 @@ impl Config {
self.opt.verbose self.opt.verbose
} }
pub fn tracing_filter_directives(&self) -> String {
let mut ret = String::new();
if let Some(directives) = self.config_file.misc.as_ref().and_then(|m| m.log_filters.as_ref()) {
ret.push_str(&directives.join(","));
}
ret.push(',');
ret.push_str(&self.opt.log_filter);
if self.verbose() {
ret.push_str(",debug");
}
ret
}
pub fn show_skipped(&self) -> bool { pub fn show_skipped(&self) -> bool {
self.opt.show_skipped self.opt.show_skipped
} }

View File

@@ -64,8 +64,6 @@ fn run() -> Result<()> {
return Ok(()); return Ok(());
} }
install_tracing(&opt.tracing_filter_directives())?;
for env in opt.env_variables() { for env in opt.env_variables() {
let mut splitted = env.split('='); let mut splitted = env.split('=');
let var = splitted.next().unwrap(); let var = splitted.next().unwrap();
@@ -84,6 +82,7 @@ fn run() -> Result<()> {
} }
let config = Config::load(opt)?; let config = Config::load(opt)?;
install_tracing(&config.tracing_filter_directives())?;
set_title(config.set_title()); set_title(config.set_title());
display_time(config.display_time()); display_time(config.display_time());
set_desktop_notifications(config.notify_each_step()); set_desktop_notifications(config.notify_each_step());