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
|
use log::{error, LevelFilter};
use serde::{Deserialize, Deserializer};
use crate::config::{failure_default, LOG_TARGET_CONFIG};
/// Debugging options
#[serde(default)]
#[derive(Deserialize, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Debug {
#[serde(default = "default_log_level", deserialize_with = "deserialize_log_level")]
pub log_level: LevelFilter,
#[serde(deserialize_with = "failure_default")]
pub print_events: bool,
/// Keep the log file after quitting
#[serde(deserialize_with = "failure_default")]
pub persistent_logging: bool,
/// Should show render timer
#[serde(deserialize_with = "failure_default")]
pub render_timer: bool,
/// Record ref test
#[serde(skip)]
pub ref_test: bool,
}
impl Default for Debug {
fn default() -> Self {
Self {
log_level: default_log_level(),
print_events: Default::default(),
persistent_logging: Default::default(),
render_timer: Default::default(),
ref_test: Default::default(),
}
}
}
fn default_log_level() -> LevelFilter {
LevelFilter::Warn
}
fn deserialize_log_level<'a, D>(deserializer: D) -> Result<LevelFilter, D::Error>
where
D: Deserializer<'a>,
{
Ok(match failure_default::<D, String>(deserializer)?.to_lowercase().as_str() {
"off" | "none" => LevelFilter::Off,
"error" => LevelFilter::Error,
"warn" => LevelFilter::Warn,
"info" => LevelFilter::Info,
"debug" => LevelFilter::Debug,
"trace" => LevelFilter::Trace,
level => {
error!(
target: LOG_TARGET_CONFIG,
"Problem with config: invalid log level {}; using level Warn", level
);
default_log_level()
},
})
}
|