Skip to content

Commit

Permalink
Merge pull request #300 from epage/other
Browse files Browse the repository at this point in the history
feat(filter): Add a Logger decorator
  • Loading branch information
epage committed Jan 19, 2024
2 parents 98abcf2 + 6c2ea80 commit 23441be
Show file tree
Hide file tree
Showing 11 changed files with 940 additions and 955 deletions.
20 changes: 20 additions & 0 deletions crates/env_filter/src/directive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use log::Level;
use log::LevelFilter;

#[derive(Debug)]
pub(crate) struct Directive {
pub(crate) name: Option<String>,
pub(crate) level: LevelFilter,
}

// Check whether a level and target are enabled by the set of directives.
pub(crate) fn enabled(directives: &[Directive], level: Level, target: &str) -> bool {
// Search for the longest match, the vector is assumed to be pre-sorted.
for directive in directives.iter().rev() {
match directive.name {
Some(ref name) if !target.starts_with(&**name) => {}
Some(..) | None => return level <= directive.level,
}
}
false
}

0 comments on commit 23441be

Please sign in to comment.