From bc2a9fe87dabc638e3607434c6e465e979965aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Wo=C5=BAniak?= Date: Wed, 4 Aug 2021 14:13:30 +0200 Subject: [PATCH 1/3] Set default log level and initialize logger before load config --- src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index f882c0e..5c8f7b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -209,6 +209,10 @@ fn change_mode(switcher: Switcher, mode: FanMode, config: Config) -> std::io::Re } fn main() -> std::io::Result<()> { + if std::env::var("RUST_LOG").is_err() { + std::env::set_var("RUST_LOG", "DEBUG"); + } + pretty_env_logger::init(); if std::fs::read(CONFIG_DIR).map_err(|e| e.kind() == ErrorKind::NotFound) == Err(true) { std::fs::create_dir_all(CONFIG_DIR)?; } @@ -216,7 +220,6 @@ fn main() -> std::io::Result<()> { let config = load_config()?; std::env::set_var("RUST_LOG", config.log_level().to_str()); - pretty_env_logger::init(); let opts: Opts = Opts::parse_args_default_or_exit(); From c110d98959dfa55669e6276639c458b9f9129f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Wo=C5=BAniak?= Date: Wed, 4 Aug 2021 16:00:28 +0200 Subject: [PATCH 2/3] Set default log level and initialize logger before load config --- src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5c8f7b1..0c60e9f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -218,8 +218,7 @@ fn main() -> std::io::Result<()> { } let config = load_config()?; - - std::env::set_var("RUST_LOG", config.log_level().to_str()); + log::set_max_level(config.log_level().to_str().parse().unwrap()); let opts: Opts = Opts::parse_args_default_or_exit(); From 09007b78ac03faeeba44d8c28f178b96ca115e08 Mon Sep 17 00:00:00 2001 From: Stefan Gehr Date: Wed, 4 Aug 2021 22:01:59 +0200 Subject: [PATCH 3/3] as_str() instead of to_str() for loglevel --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index a7a8746..1113874 100644 --- a/src/main.rs +++ b/src/main.rs @@ -89,7 +89,7 @@ fn main() -> std::io::Result<()> { } let config = load_config()?; - log::set_max_level(config.log_level().to_str().parse().unwrap()); + log::set_max_level(config.log_level().as_str().parse().unwrap()); let opts: Opts = Opts::parse_args_default_or_exit();