Browse Source

Additional logging by default

* made the rsddns namespace log at info by default
* Added messages to the configuration errors
* made configuration error cause logging
develop
Drew Short 6 years ago
parent
commit
e4f1c09ada
  1. 22
      src/config.rs
  2. 7
      src/main.rs

22
src/config.rs

@ -78,13 +78,23 @@ fn get_default_config() -> Config {
} }
#[derive(Debug)] #[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 Error for ConfigError {}
impl fmt::Display for ConfigError { impl fmt::Display for ConfigError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 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<Config, ConfigError> {
match serde_yaml::from_str(yaml_str) { match serde_yaml::from_str(yaml_str) {
Ok(v) => Result::Ok(v), Ok(v) => Result::Ok(v),
// File wasn't valid Config/YAML // 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<Config, ConfigError> {
read_config(&contents) read_config(&contents)
} else { } else {
// File was empty // File was empty
Result::Err(ConfigError{})
Result::Err(ConfigError::new("Configuration file was empty"))
} }
}, },
// File couldn't be read // 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 // File Doesn't exist
Err(_e) => Result::Err(ConfigError{})
Err(_e) => Result::Err(ConfigError::new(&format!("Configuration file doesn't exist \"{}\"", path)))
} }
} }

7
src/main.rs

@ -32,7 +32,7 @@ lazy_static! {
fn main() { fn main() {
match std::env::var("RUST_LOG") { match std::env::var("RUST_LOG") {
Ok(_) => (), 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(); 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_path: &str = args.value_of("config").unwrap_or("/etc/rsddns/rsddns.yml");
let config = match config::load_config(config_path) { let config = match config::load_config(config_path) {
Ok(c) => Option::Some(c), Ok(c) => Option::Some(c),
Err(_e) => Option::None
Err(e) => {
error!("{}", e);
Option::None
}
}; };
let host = String::from(match &config { let host = String::from(match &config {

Loading…
Cancel
Save