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
use simplelog::{self, CombinedLogger, LevelFilter, TermLogger};
use error::FrameworkError;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct LoggingConfig {
level_filter: LevelFilter,
simplelog_config: simplelog::Config,
}
impl LoggingConfig {
pub fn verbose() -> Self {
LevelFilter::Debug.into()
}
}
impl Default for LoggingConfig {
fn default() -> Self {
LevelFilter::Info.into()
}
}
impl From<LevelFilter> for LoggingConfig {
fn from(level_filter: LevelFilter) -> LoggingConfig {
Self {
level_filter,
simplelog_config: Default::default(),
}
}
}
pub fn init(config: LoggingConfig) -> Result<(), FrameworkError> {
let LoggingConfig {
level_filter,
simplelog_config,
} = config;
if let Some(logger) = TermLogger::new(level_filter, simplelog_config) {
CombinedLogger::init(vec![logger]).unwrap()
}
Ok(())
}