diff options
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs index 2ba10ec..c110825 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,6 +7,7 @@ use std::{ }; use anyhow::bail; +use log::LevelFilter; use rumqttc::{AsyncClient, EventLoop, MqttOptions, QoS}; use serde::{ de::{self, Visitor}, @@ -15,6 +16,23 @@ use serde::{ use crate::PROGRAM; +#[derive(Deserialize, Debug, PartialEq)] +pub struct Logging { + #[serde(default = "default_level_filter")] + pub level: LevelFilter, + #[serde(default)] // Off + pub timestamps: bool, +} + +impl Default for Logging { + fn default() -> Self { + Self { + level: default_level_filter(), + timestamps: bool::default(), + } + } +} + #[derive(Deserialize, Debug)] pub struct Credentials { pub username: String, @@ -41,6 +59,10 @@ fn default_timeout() -> Duration { Duration::from_secs(60) } +fn default_level_filter() -> LevelFilter { + LevelFilter::Info +} + #[allow(clippy::enum_variant_names)] #[derive(Deserialize, Debug)] #[serde(remote = "QoS", rename_all = "kebab-case")] @@ -248,6 +270,8 @@ pub struct Config { pub qos: QoS, #[serde(default = "default_timeout", deserialize_with = "deserialize_timeout")] pub timeout: Duration, + #[serde(default)] + pub log: Logging, pub credentials: Option<Credentials>, #[serde(default = "default_id")] pub id: String, @@ -317,6 +341,10 @@ mod tests { username = "testuser" password = "testpassword" + [log] + level = "trace" + timestamps = true + [routes] "topic/map" = { programs = [ ["/bin/program1"], @@ -341,6 +369,9 @@ mod tests { assert_eq!(creds.username, "testuser"); assert_eq!(creds.password, "testpassword"); + assert_eq!(config.log.level, LevelFilter::Trace); + assert_eq!(config.log.timestamps, true); + assert_eq!(config.routes.len(), 2); let route_map = config.routes.get("topic/map").unwrap(); @@ -377,6 +408,7 @@ mod tests { assert_eq!(config.id, default_id()); assert_eq!(config.timeout, default_timeout()); assert!(config.credentials.is_none()); + assert_eq!(config.log, Logging::default()); assert!(config.routes.is_empty()); } |