| 1 | use log::Level; |
| 2 | use log::LevelFilter; |
| 3 | |
| 4 | #[derive (Debug)] |
| 5 | pub(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. |
| 11 | pub(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: &Directive in directives.iter().rev() { |
| 14 | match directive.name { |
| 15 | Some(ref name: &String) if !target.starts_with(&**name) => {} |
| 16 | Some(..) | None => return level <= directive.level, |
| 17 | } |
| 18 | } |
| 19 | false |
| 20 | } |
| 21 | |