Skip to content

Commit

Permalink
filter log messages from the library separately
Browse files Browse the repository at this point in the history
  • Loading branch information
evertedsphere committed Dec 21, 2023
1 parent cee7be6 commit 7139c09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion topiary-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ readme.workspace = true
license.workspace = true

[[bin]]
name = "topiary"
name = "topiary_cli"
path = "src/main.rs"

[dependencies]
Expand Down
21 changes: 13 additions & 8 deletions topiary-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,20 @@ pub fn get_args() -> CLIResult<Cli> {
let mut args = Cli::parse();

// This is the earliest point that we can initialise the logger, from the --verbose flags,
// before any fallible operations have started
// before any fallible operations have started.
//
// Be more strict with logs coming with the library; prefer to display less of them.
let (global_filter_level, library_filter_level) = match args.global.verbose {
0 => (LevelFilter::Error, LevelFilter::Error),
1 => (LevelFilter::Warn, LevelFilter::Warn),
2 => (LevelFilter::Info, LevelFilter::Warn),
3 => (LevelFilter::Debug, LevelFilter::Warn),
_ => (LevelFilter::Trace, LevelFilter::Trace),
};

env_logger::Builder::new()
.filter_level(match args.global.verbose {
0 => LevelFilter::Error,
1 => LevelFilter::Warn,
2 => LevelFilter::Info,
3 => LevelFilter::Debug,
_ => LevelFilter::Trace,
})
.filter_level(global_filter_level)
.filter_module("topiary", library_filter_level)
.init();

// NOTE We do not check that input files are actual files (with Path::is_file), because that
Expand Down

0 comments on commit 7139c09

Please sign in to comment.