Skip to content

Commit

Permalink
use single entry with ConfigLogSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
filip-dulic-bloxico committed Apr 6, 2021
1 parent a28f271 commit fa1d422
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
5 changes: 1 addition & 4 deletions jormungandr/src/settings/start/config.rs
Expand Up @@ -53,16 +53,13 @@ pub struct Config {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct ConfigLogSettingsEntry {
pub struct ConfigLogSettings {
#[serde(with = "filter_level_opt_serde")]
pub level: Option<LevelFilter>,
pub format: Option<LogFormat>,
pub output: Option<LogOutput>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ConfigLogSettings(pub Vec<ConfigLogSettingsEntry>);

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct P2pConfig {
Expand Down
26 changes: 9 additions & 17 deletions jormungandr/src/settings/start/mod.rs
Expand Up @@ -72,23 +72,15 @@ impl RawSettings {
let mut info_msgs: Vec<String> = Vec::new();

// Read log settings from the config file path.
if let Some(log) = self.config.as_ref().and_then(|cfg| cfg.log.as_ref()) {
if let Some(cfg) = log.0.first() {
if log.0.len() > 1 {
info_msgs.push(format!(
"only one entry for log settings allowed, ignoring these: {:?}",
&log.0[1..],
));
}
if let Some(level) = cfg.level {
log_config.level = level;
}
if let Some(format) = cfg.format {
log_config.format = format;
}
if let Some(output) = &cfg.output {
log_config.output = output.clone();
}
if let Some(cfg) = self.config.as_ref().and_then(|cfg| cfg.log.as_ref()) {
if let Some(level) = cfg.level {
log_config.level = level;
}
if let Some(format) = cfg.format {
log_config.format = format;
}
if let Some(output) = &cfg.output {
log_config.output = output.clone();
}
}

Expand Down
Expand Up @@ -212,11 +212,11 @@ impl ConfigurationBuilder {
}

pub fn with_log_path(&mut self, path: PathBuf) -> &mut Self {
self.with_log(Log(vec![LogEntry {
self.with_log(Log(LogEntry {
format: "json".to_string(),
level: "debug".to_string(),
output: LogOutput::File(path),
}]))
}))
}

pub fn without_log(&mut self) -> &mut Self {
Expand Down

0 comments on commit fa1d422

Please sign in to comment.