Skip to content

Commit

Permalink
simple_logger update and configurable DEBUG flag
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossless committed Jan 12, 2024
1 parent bb43762 commit a48503f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ features = ["linux-static-libusb"]

[dependencies.log]
version = "0.4"
features = ["max_level_debug", "release_max_level_info"]
features = ["max_level_debug"]

[dependencies.simple_logger]
version = "4.3"
Expand Down
22 changes: 20 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
fs,
env, fs,
io::{self, Read},
process::ExitCode,
};
Expand Down Expand Up @@ -66,8 +66,26 @@ fn cli() -> Command {
);
}

fn get_log_level() -> log::LevelFilter {
return if let Ok(debug) = env::var("DEBUG") {
if debug == "1" {
log::LevelFilter::Debug
} else {
log::LevelFilter::Info
}
} else {
#[cfg(debug_assertions)]
return log::LevelFilter::Debug;
#[cfg(not(debug_assertions))]
log::LevelFilter::Info
};
}

fn err_main() -> Result<(), CLIError> {
SimpleLogger::new().init().unwrap();
SimpleLogger::new()
.with_level(get_log_level())
.init()
.unwrap();

let matches = cli().get_matches();

Expand Down

0 comments on commit a48503f

Please sign in to comment.