Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quickstart log4rs.yaml sample #332

Merged
merged 4 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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())
}
}