diff --git a/crates/env_filter/src/directive.rs b/crates/env_filter/src/directive.rs new file mode 100644 index 0000000..3721ef7 --- /dev/null +++ b/crates/env_filter/src/directive.rs @@ -0,0 +1,20 @@ +use log::Level; +use log::LevelFilter; + +#[derive(Debug)] +pub(crate) struct Directive { + pub(crate) name: Option, + 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 +} diff --git a/crates/env_filter/src/lib.rs b/crates/env_filter/src/lib.rs index 3d97d38..41b71f8 100644 --- a/crates/env_filter/src/lib.rs +++ b/crates/env_filter/src/lib.rs @@ -50,6 +50,7 @@ //! } //! ``` +mod directive; mod op; mod parser; @@ -57,8 +58,10 @@ use std::env; use std::fmt; use std::mem; -use log::{Level, LevelFilter, Metadata, Record}; +use log::{LevelFilter, Metadata, Record}; +use directive::enabled; +use directive::Directive; use op::FilterOp; use parser::parse_spec; @@ -210,12 +213,6 @@ impl fmt::Debug for Builder { } } -#[derive(Debug)] -struct Directive { - name: Option, - level: LevelFilter, -} - /// A log filter. /// /// This struct can be used to determine whether or not a log record @@ -286,18 +283,6 @@ impl fmt::Debug for Filter { } } -// Check whether a level and target are enabled by the set of directives. -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 -} - #[cfg(test)] mod tests { use log::{Level, LevelFilter};