Skip to content

Commit

Permalink
Fix logging
Browse files Browse the repository at this point in the history
Clap occurrences 0 case was overriding the computed log_level
(config was never considered).
Also all log messages were discareded due log's max level being set to
Off. It should be set to the maximum filter level, thus letting
fern filters decide what to log.
  • Loading branch information
alcroito committed Feb 21, 2021
1 parent 4313627 commit 3743dc0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn config_with_args(clap_matches: &ArgMatches<'static>) -> Result<Config> {
Ok(config)
}

type OccurencesFn<T> = Box<dyn FnMut(u64) -> T>;
type OccurencesFn<T> = Box<dyn FnMut(u64) -> Option<T>>;
pub struct ValueBuilder<'clap, 'toml, T> {
key: String,
value: Option<T>,
Expand Down Expand Up @@ -179,7 +179,7 @@ impl<'clap, 'toml, T: std::str::FromStr> ValueBuilder<'clap, 'toml, T> {
if let Some((arg_matches, ref option_name, ref mut clap_fn)) = self.clap_occurrences_option
{
let occurences_value = arg_matches.occurrences_of(option_name);
self.value = Some(clap_fn(occurences_value));
self.value = clap_fn(occurences_value);
}

self
Expand Down Expand Up @@ -374,10 +374,10 @@ impl<'clap> Builder<'clap> {
self.clap_matches,
LOG_LEVEL_VERBOSITY_SHORT,
Box::new(|count| match count {
0 => log::LevelFilter::Info,
1 => log::LevelFilter::Debug,
2 => log::LevelFilter::Trace,
_ => log::LevelFilter::Trace,
0 => None,
1 => Some(log::LevelFilter::Debug),
2 => Some(log::LevelFilter::Trace),
_ => Some(log::LevelFilter::Trace),
}),
)
.with_config_value(self.toml_table.as_ref())
Expand Down
3 changes: 3 additions & 0 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ pub fn setup_early_logger() -> Result<()> {
log_reroute::init()?;
let early_logger = create_fern_dispatch(&log::LevelFilter::Trace);
log_reroute::reroute_boxed(early_logger);
// This is needed to activate all the log::log!() macro calls, otherwise
// all the calls are no-ops.
log::set_max_level(log::LevelFilter::Trace);
Ok(())
}

Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ fn main() -> Result<()> {
fn start_daemon(config: Config) -> Result<()> {
setup_logger(&config.log_level)?;
setup_forceful_term_signal_handling()?;

let updater = DigitalOceanUpdater::new(config);
let exit_flag = updater.exit_flag();
let app_thread = updater.start_update_loop_detached();
Expand Down

0 comments on commit 3743dc0

Please sign in to comment.