1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
pub trait Filter: Send + Sync {
fn filter(&self, record: &log::Record) -> bool;
}
pub struct NoFilter {}
impl Filter for NoFilter {
fn filter(&self, module: &log::Record) -> bool {
return false;
}
}
pub struct ModuleFilter {
pub include: Option<Vec<String>>,
pub exclude: Option<Vec<String>>,
}
impl ModuleFilter {
pub fn new_include(arg: Vec<String>) -> Self {
Self {
include: Some(arg),
exclude: None,
}
}
pub fn new_exclude(arg: Vec<String>) -> Self {
Self {
include: None,
exclude: Some(arg),
}
}
pub fn new(include: Option<Vec<String>>, exclude: Option<Vec<String>>) -> Self {
Self { include, exclude }
}
}
impl Filter for ModuleFilter {
fn filter(&self, record: &log::Record) -> bool {
let module = record.module_path().unwrap_or("");
if self.include.is_some() {
for x in self.include.as_ref().unwrap() {
if module.contains(x) {
return false;
}
}
return true;
}
if self.exclude.is_some() {
for x in self.exclude.as_ref().unwrap() {
if module.contains(x) {
return true;
}
}
return false;
}
return false;
}
}