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
use ::yaml::{YamlEmitter};
use ::config::{ConfigFile, ConfigError};
use log4rs;
pub use log4rs::init_config;
#[derive(Debug)]
pub struct LoggingConfig;
impl LoggingConfig {
pub fn config_logging(config: &ConfigFile) -> Result<log4rs::config::Config, ConfigError> {
if !config["logging"].is_badvalue() {
let mut log_config_buf = String::new();
{
let mut log_emitter = YamlEmitter::new(&mut log_config_buf);
log_emitter.dump(&config["logging"])?;
}
let log_config_str = log_config_buf.as_str();
let log_config = log4rs::file::Config::parse(log_config_str,
log4rs::file::Format::Yaml,
&log4rs::file::Deserializers::default())?;
Ok(log_config.into_config())
} else {
Err(ConfigError::MissingComponent("logging".to_string()))
}
}
}