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 50
50
//! }
51
51
//! ```
52
52
53
+ mod directive;
53
54
mod op;
54
55
mod parser;
55
56
56
57
use std:: env;
57
58
use std:: fmt;
58
59
use std:: mem;
59
60
60
- use log:: { Level , LevelFilter , Metadata , Record } ;
61
+ use log:: { LevelFilter , Metadata , Record } ;
61
62
63
+ use directive:: enabled;
64
+ use directive:: Directive ;
62
65
use op:: FilterOp ;
63
66
use parser:: parse_spec;
64
67
@@ -210,12 +213,6 @@ impl fmt::Debug for Builder {
210
213
}
211
214
}
212
215
213
- #[ derive( Debug ) ]
214
- struct Directive {
215
- name : Option < String > ,
216
- level : LevelFilter ,
217
- }
218
-
219
216
/// A log filter.
220
217
///
221
218
/// This struct can be used to determine whether or not a log record
@@ -286,18 +283,6 @@ impl fmt::Debug for Filter {
286
283
}
287
284
}
288
285
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
-
301
286
#[ cfg( test) ]
302
287
mod tests {
303
288
use log:: { Level , LevelFilter } ;
You can’t perform that action at this time.
0 commit comments