From e4f1c09adaccd396694c3d3fd433ccb76209437e Mon Sep 17 00:00:00 2001 From: Drew Short Date: Wed, 5 Dec 2018 15:38:36 -0600 Subject: [PATCH] Additional logging by default * made the rsddns namespace log at info by default * Added messages to the configuration errors * made configuration error cause logging --- src/config.rs | 22 ++++++++++++++++------ src/main.rs | 7 +++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/config.rs b/src/config.rs index 459439d..482d9e5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -78,13 +78,23 @@ fn get_default_config() -> Config { } #[derive(Debug)] -pub struct ConfigError; +pub struct ConfigError { + description: String +} + +impl ConfigError { + fn new(description: &str) -> ConfigError { + ConfigError { + description: String::from(description) + } + } +} impl Error for ConfigError {} impl fmt::Display for ConfigError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Configuration Error") + write!(f, "Configuration Error: {}", self.description) } } @@ -92,7 +102,7 @@ fn read_config(yaml_str: &str) -> Result { match serde_yaml::from_str(yaml_str) { Ok(v) => Result::Ok(v), // File wasn't valid Config/YAML - Err(_e) => Result::Err(ConfigError{}) + Err(_e) => Result::Err(ConfigError::new("Configuration file was invalid")) } } @@ -106,14 +116,14 @@ pub fn load_config(path: &str) -> Result { read_config(&contents) } else { // File was empty - Result::Err(ConfigError{}) + Result::Err(ConfigError::new("Configuration file was empty")) } }, // File couldn't be read - Err(_e) => Result::Err(ConfigError{}) + Err(_e) => Result::Err(ConfigError::new("Configuration file could not be read")) } }, // File Doesn't exist - Err(_e) => Result::Err(ConfigError{}) + Err(_e) => Result::Err(ConfigError::new(&format!("Configuration file doesn't exist \"{}\"", path))) } } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index cabf74a..4eb8696 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,7 +32,7 @@ lazy_static! { fn main() { match std::env::var("RUST_LOG") { Ok(_) => (), - Err(_) => std::env::set_var("RUST_LOG", "actix_web=info"), + Err(_) => std::env::set_var("RUST_LOG", "error,actix_web=info,rsddns=info") } env_logger::init(); @@ -75,7 +75,10 @@ fn main() { let config_path: &str = args.value_of("config").unwrap_or("/etc/rsddns/rsddns.yml"); let config = match config::load_config(config_path) { Ok(c) => Option::Some(c), - Err(_e) => Option::None + Err(e) => { + error!("{}", e); + Option::None + } }; let host = String::from(match &config {