Set default log level and initialize logger before load config

This commit is contained in:
Adrian Woźniak 2021-08-04 14:13:30 +02:00
parent 90e1dcdad6
commit bc2a9fe87d
No known key found for this signature in database
GPG Key ID: 0012845A89C7352B

View File

@ -209,6 +209,10 @@ fn change_mode(switcher: Switcher, mode: FanMode, config: Config) -> std::io::Re
} }
fn main() -> std::io::Result<()> { 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) { if std::fs::read(CONFIG_DIR).map_err(|e| e.kind() == ErrorKind::NotFound) == Err(true) {
std::fs::create_dir_all(CONFIG_DIR)?; std::fs::create_dir_all(CONFIG_DIR)?;
} }
@ -216,7 +220,6 @@ fn main() -> std::io::Result<()> {
let config = load_config()?; let config = load_config()?;
std::env::set_var("RUST_LOG", config.log_level().to_str()); std::env::set_var("RUST_LOG", config.log_level().to_str());
pretty_env_logger::init();
let opts: Opts = Opts::parse_args_default_or_exit(); let opts: Opts = Opts::parse_args_default_or_exit();