Skip to content

Commit

Permalink
Fix quickstart log4rs.yaml sample (#332)
Browse files Browse the repository at this point in the history
* fix quickstart

* add test to ensure readme sample file is ok

* make test compatible for windows

* do changes to satisfy CI pipeline
  • Loading branch information
vladimirr9 committed Dec 17, 2023
1 parent ebb9123 commit 58b92c8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 19 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ indent_size = false

[*.md]
trim_trailing_whitespace = false
indent_size = 2

[*.{yml,yaml}]
indent_size = 2
Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ log4rs.yaml:
```yaml
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
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
```

lib.rs:
Expand Down
27 changes: 27 additions & 0 deletions src/config/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ fn logger_additive_default() -> bool {
#[cfg(test)]
#[allow(unused_imports)]
mod test {
use std::fs;

use super::*;

#[test]
Expand Down Expand Up @@ -500,4 +502,29 @@ loggers:
fn empty() {
::serde_yaml::from_str::<RawConfig>("{}").unwrap();
}

#[cfg(windows)]
#[allow(dead_code)]
const LINE_ENDING: &'static str = "\r\n";
#[cfg(not(windows))]
#[allow(dead_code)]
const LINE_ENDING: &'static str = "\n";

#[test]
#[cfg(feature = "yaml_format")]
fn readme_sample_file_is_ok() {
let readme = fs::read_to_string("./README.md").expect("README file exists");
let sample_file = &readme[readme
.find("log4rs.yaml:")
.expect("Sample file exists and is called log4rs.yaml")..];
let config_start_string = format!("{}```yaml{}", LINE_ENDING, LINE_ENDING);
let config_end_string = format!("{}```{}", LINE_ENDING, LINE_ENDING);
let config_start =
sample_file.find(&config_start_string).unwrap() + config_start_string.len();
let config_end = sample_file.find(&config_end_string).unwrap();
let config_str = sample_file[config_start..config_end].trim();

let config = ::serde_yaml::from_str::<RawConfig>(config_str);
assert!(config.is_ok())
}
}

0 comments on commit 58b92c8

Please sign in to comment.