File tree Expand file tree Collapse file tree 2 files changed +24
-19
lines changed
Expand file tree Collapse file tree 2 files changed +24
-19
lines changed Original file line number Diff line number Diff line change 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 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+ }
Original file line number Diff line number Diff line change 5050//! }
5151//! ```
5252
53+ mod directive;
5354mod op;
5455mod parser;
5556
5657use std:: env;
5758use std:: fmt;
5859use std:: mem;
5960
60- use log:: { Level , LevelFilter , Metadata , Record } ;
61+ use log:: { LevelFilter , Metadata , Record } ;
6162
63+ use directive:: enabled;
64+ use directive:: Directive ;
6265use op:: FilterOp ;
6366use parser:: parse_spec;
6467
@@ -210,12 +213,6 @@ impl fmt::Debug for Builder {
210213 }
211214}
212215
213- #[ derive( Debug ) ]
214- struct Directive {
215- name : Option < String > ,
216- level : LevelFilter ,
217- }
218-
219216/// A log filter.
220217///
221218/// This struct can be used to determine whether or not a log record
@@ -286,18 +283,6 @@ impl fmt::Debug for Filter {
286283 }
287284}
288285
289- // Check whether a level and target are enabled by the set of directives.
290- fn enabled ( directives : & [ Directive ] , level : Level , target : & str ) -> bool {
291- // Search for the longest match, the vector is assumed to be pre-sorted.
292- for directive in directives. iter ( ) . rev ( ) {
293- match directive. name {
294- Some ( ref name) if !target. starts_with ( & * * name) => { }
295- Some ( ..) | None => return level <= directive. level ,
296- }
297- }
298- false
299- }
300-
301286#[ cfg( test) ]
302287mod tests {
303288 use log:: { Level , LevelFilter } ;
You can’t perform that action at this time.
0 commit comments