estk / log4rs

A highly configurable logging framework for Rust
Apache License 2.0
973 stars 143 forks source link

Investigate and Resolve issues with Raw Config Deserializer #334

Closed bconn98 closed 6 months ago

bconn98 commented 7 months ago

The following config is deserialized as valid and should not. Discovered while testing #332

refresh_rate: 30 seconds
appenders:
  stdout:
    kind: console
  requests:
    kind: file
    path: "log/requests.log"
    encoder:
      pattern: "{d} - {m}{n}"
    root:
    level: warn
    appenders:
        - stdout
    loggers:
    app::backend::db:
        level: info
    app::requests:
        level: info
        appenders:
        - requests
        additive: false
bconn98 commented 6 months ago

The bug was that we just verified serde could parse the config, not that our tool liked the config. Suggesting the following patch to resolve:

diff --git a/src/config/raw.rs b/src/config/raw.rs
index 77963ed..171d1a1 100644
--- a/src/config/raw.rs
+++ b/src/config/raw.rs
@@ -525,6 +525,7 @@ loggers:
         let config_str = sample_file[config_start..config_end].trim();

         let config = ::serde_yaml::from_str::<RawConfig>(config_str);
-        assert!(config.is_ok())
+        assert!(config.is_ok());
+        assert!(crate::init_raw_config(config.unwrap()).is_ok());
     }
 }