-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(filter): Pull out directive mod
- Loading branch information
Showing
2 changed files
with
24 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters