-
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.
Merge pull request #300 from epage/other
feat(filter): Add a Logger decorator
- Loading branch information
Showing
11 changed files
with
940 additions
and
955 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 | ||
} |
Oops, something went wrong.