~matthiasbeyer/imag

fb8b50fa9a75b50becf9576c22f0041f9b551fea — Matthias Beyer 2 years ago 185ec25
Remove boilerplate by enabling serde in "log" dependency

This patch adds the "serde" feature to the "log" dependency, so we can
deserialize logging levels directly into "log" types.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2 files changed, 2 insertions(+), 32 deletions(-)

M lib/core/libimagrt/Cargo.toml
M lib/core/libimagrt/src/logger.rs
M lib/core/libimagrt/Cargo.toml => lib/core/libimagrt/Cargo.toml +1 -1
@@ 45,7 45,7 @@ features = ["suggestions", "color", "wrap_help"]
[dependencies.log]
version = "0.4"
default-features = false
features = ["std"]
features = ["std", "serde"]

[dependencies.handlebars]
version          = "^1.0.5"

M lib/core/libimagrt/src/logger.rs => lib/core/libimagrt/src/logger.rs +1 -31
@@ 355,41 355,11 @@ fn aggregate_module_settings(_matches: &ArgMatches, config: Option<&Value>)
    #[derive(Serialize, Deserialize, Debug)]
    struct LoggingModuleConfig {
        pub destinations: Option<Vec<String>>,
        pub level: Option<LogLevel>,
        pub level: Option<Level>,
        pub enabled: bool,
    }

    #[derive(Serialize, Deserialize, Debug)]
    enum LogLevel {
        #[serde(rename = "trace")]
        Trace,

        #[serde(rename = "debug")]
        Debug,

        #[serde(rename = "info")]
        Info,

        #[serde(rename = "warn")]
        Warn,

        #[serde(rename = "error")]
        Error,
    }

    impl Into<Level> for LogLevel {
        fn into(self) -> Level {
            match self {
                LogLevel::Trace => Level::Trace,
                LogLevel::Debug => Level::Debug,
                LogLevel::Info  => Level::Info,
                LogLevel::Warn  => Level::Warn,
                LogLevel::Error => Level::Error,
            }
        }
    }

    #[derive(Serialize, Deserialize, Debug)]
    struct LoggingModuleConfigMap(BTreeMap<String, LoggingModuleConfig>);

    impl<'a> Partial<'a> for LoggingModuleConfigMap {