env_filter/directive.rs
1use log::Level;
2use log::LevelFilter;
3
4#[derive(Debug)]
5pub(crate) struct Directive {
6 pub(crate) name: Option<String>,
7 pub(crate) level: LevelFilter,
8}
9
10// Check whether a level and target are enabled by the set of directives.
11pub(crate) fn enabled(directives: &[Directive], level: Level, target: &str) -> bool {
12 // Search for the longest match, the vector is assumed to be pre-sorted.
13 for directive in directives.iter().rev() {
14 match directive.name {
15 Some(ref name) if !target.starts_with(&**name) => {}
16 Some(..) | None => return level <= directive.level,
17 }
18 }
19 false
20}