From 12d29469d9048dcb3def2e29c0271f7c3b538141 Mon Sep 17 00:00:00 2001 From: bconn98 Date: Thu, 29 Feb 2024 23:44:48 -0500 Subject: [PATCH 1/3] chore: clippy fixes + msrv bump --- .github/workflows/main.yml | 4 ++-- Cargo.toml | 2 +- README.md | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b8219b46..1f58427f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - rust_versions: ["stable", "1.69"] + rust_versions: ["stable", "1.70"] os: [ubuntu-latest, windows-latest] steps: - name: Checkout the source code @@ -63,7 +63,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust_versions: ["stable", "1.69"] + rust_versions: ["stable", "1.70"] steps: - name: Checkout the source code uses: actions/checkout@v4 diff --git a/Cargo.toml b/Cargo.toml index 9f648269..cfbb236a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/estk/log4rs" readme = "README.md" keywords = ["log", "logger", "logging", "log4"] edition = "2018" -rust-version = "1.69" +rust-version = "1.70" [features] default = ["all_components", "config_parsing", "yaml_format"] diff --git a/README.md b/README.md index c35baf4d..496a7fa1 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![crates.io](https://img.shields.io/crates/v/log4rs.svg)](https://crates.io/crates/log4rs) [![License: MIT OR Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](#license) ![CI](https://github.com/estk/log4rs/workflows/CI/badge.svg) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.69+-green.svg)](https://github.com/estk/log4rs#rust-version-requirements) +[![Minimum rustc version](https://img.shields.io/badge/rustc-1.70+-green.svg)](https://github.com/estk/log4rs#rust-version-requirements) log4rs is a highly configurable logging framework modeled after Java's Logback and log4j libraries. @@ -54,7 +54,7 @@ fn main() { ## Rust Version Requirements -1.69 +1.70 ## Building for Dev From 3b6a5bbad307421d1bce3d5dcd63e554cac97b02 Mon Sep 17 00:00:00 2001 From: bconn98 Date: Sat, 2 Mar 2024 19:08:56 -0500 Subject: [PATCH 2/3] chore: backout msrv bump, knock toml down --- .github/workflows/main.yml | 4 ++-- Cargo.toml | 2 +- README.md | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1f58427f..b8219b46 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - rust_versions: ["stable", "1.70"] + rust_versions: ["stable", "1.69"] os: [ubuntu-latest, windows-latest] steps: - name: Checkout the source code @@ -63,7 +63,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust_versions: ["stable", "1.70"] + rust_versions: ["stable", "1.69"] steps: - name: Checkout the source code uses: actions/checkout@v4 diff --git a/Cargo.toml b/Cargo.toml index cfbb236a..9f648269 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/estk/log4rs" readme = "README.md" keywords = ["log", "logger", "logging", "log4"] edition = "2018" -rust-version = "1.70" +rust-version = "1.69" [features] default = ["all_components", "config_parsing", "yaml_format"] diff --git a/README.md b/README.md index 496a7fa1..c35baf4d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![crates.io](https://img.shields.io/crates/v/log4rs.svg)](https://crates.io/crates/log4rs) [![License: MIT OR Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](#license) ![CI](https://github.com/estk/log4rs/workflows/CI/badge.svg) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.70+-green.svg)](https://github.com/estk/log4rs#rust-version-requirements) +[![Minimum rustc version](https://img.shields.io/badge/rustc-1.69+-green.svg)](https://github.com/estk/log4rs#rust-version-requirements) log4rs is a highly configurable logging framework modeled after Java's Logback and log4j libraries. @@ -54,7 +54,7 @@ fn main() { ## Rust Version Requirements -1.70 +1.69 ## Building for Dev From 1260ca0d7a93ccaaf4f651ab5964c339be4fa4d7 Mon Sep 17 00:00:00 2001 From: bconn98 Date: Sun, 3 Mar 2024 22:33:43 -0500 Subject: [PATCH 3/3] test: add new integration tests --- test_cfgs/malformed_appender.yml | 13 ++++++++ test_cfgs/test.json | 51 +++++++++++++++++++++++++++++++ test_cfgs/test.toml | 39 +++++++++++++++++++++++ test_cfgs/test.yml | 36 ++++++++++++++++++++++ tests/color_control.rs | 24 --------------- tests/init_json_config.rs | 12 ++++++++ tests/init_malformed_appenders.rs | 14 +++++++++ tests/init_toml_config.rs | 12 ++++++++ tests/init_yaml_config.rs | 12 ++++++++ 9 files changed, 189 insertions(+), 24 deletions(-) create mode 100755 test_cfgs/malformed_appender.yml create mode 100644 test_cfgs/test.json create mode 100644 test_cfgs/test.toml create mode 100644 test_cfgs/test.yml delete mode 100644 tests/color_control.rs create mode 100755 tests/init_json_config.rs create mode 100755 tests/init_malformed_appenders.rs create mode 100755 tests/init_toml_config.rs create mode 100755 tests/init_yaml_config.rs diff --git a/test_cfgs/malformed_appender.yml b/test_cfgs/malformed_appender.yml new file mode 100755 index 00000000..f9db7d57 --- /dev/null +++ b/test_cfgs/malformed_appender.yml @@ -0,0 +1,13 @@ +refresh_rate: 5 seconds + +appenders: + file: + kind: file + pah: "log/file.log" + encoder: + pattern: "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}" + +root: + level: info + appenders: + - file diff --git a/test_cfgs/test.json b/test_cfgs/test.json new file mode 100644 index 00000000..b93f08c9 --- /dev/null +++ b/test_cfgs/test.json @@ -0,0 +1,51 @@ +{ + "refresh_rate": "5 seconds", + "appenders": { + "stdout": { + "kind": "console", + "encoder": { + "pattern": "{d(%+)(utc)} [{f}:{L}] {h({l})} {M}:{m}{n}" + }, + "filters": [ + { + "kind": "threshold", + "level": "info" + } + ] + }, + "file": { + "kind": "file", + "path": "log/file.log", + "encoder": { + "pattern": "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}" + } + }, + "rollingfile": { + "kind": "rolling_file", + "path": "log/rolling_file.log", + "encoder": { + "pattern": "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}" + }, + "policy": { + "trigger": { + "kind": "time", + "interval": "1 minute" + }, + "roller": { + "kind": "fixed_window", + "pattern": "log/old-rolling_file-{}.log", + "base": 0, + "count": 2 + } + } + } + }, + "root": { + "level": "info", + "appenders": [ + "stdout", + "file", + "rollingfile" + ] + } +} diff --git a/test_cfgs/test.toml b/test_cfgs/test.toml new file mode 100644 index 00000000..dc1f10da --- /dev/null +++ b/test_cfgs/test.toml @@ -0,0 +1,39 @@ +refresh_rate = "5 seconds" + +[appenders.stdout] +kind = "console" + + [appenders.stdout.encoder] + pattern = "{d(%+)(utc)} [{f}:{L}] {h({l})} {M}:{m}{n}" + + [[appenders.stdout.filters]] + kind = "threshold" + level = "info" + +[appenders.file] +kind = "file" +path = "log/file.log" + + [appenders.file.encoder] + pattern = "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}" + +[appenders.rollingfile] +kind = "rolling_file" +path = "log/rolling_file.log" + + [appenders.rollingfile.encoder] + pattern = "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}" + +[appenders.rollingfile.policy.trigger] +kind = "time" +interval = "1 minute" + +[appenders.rollingfile.policy.roller] +kind = "fixed_window" +pattern = "log/old-rolling_file-{}.log" +base = 0 +count = 2 + +[root] +level = "info" +appenders = [ "stdout", "file", "rollingfile" ] diff --git a/test_cfgs/test.yml b/test_cfgs/test.yml new file mode 100644 index 00000000..47d18ccd --- /dev/null +++ b/test_cfgs/test.yml @@ -0,0 +1,36 @@ +refresh_rate: 5 seconds + +appenders: + stdout: + kind: console + encoder: + pattern: "{d(%+)(utc)} [{f}:{L}] {h({l})} {M}:{m}{n}" + filters: + - kind: threshold + level: info + file: + kind: file + path: "log/file.log" + encoder: + pattern: "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}" + rollingfile: + kind: rolling_file + path: "log/rolling_file.log" + encoder: + pattern: "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}" + policy: + trigger: + kind: time + interval: 1 minute + roller: + kind: fixed_window + pattern: "log/old-rolling_file-{}.log" + base: 0 + count: 2 + +root: + level: info + appenders: + - stdout + - file + - rollingfile diff --git a/tests/color_control.rs b/tests/color_control.rs deleted file mode 100644 index 344f032f..00000000 --- a/tests/color_control.rs +++ /dev/null @@ -1,24 +0,0 @@ -use std::process::Command; - -fn execute_test(env_key: &str, env_val: &str) { - let mut child_proc = Command::new("cargo") - .args(&["run", "--example", "compile_time_config"]) - .env(env_key, env_val) - .spawn() - .expect("Cargo command failed to start"); - - let ecode = child_proc.wait().expect("failed to wait on child"); - - assert!(ecode.success()); -} - -// Maintaining as a single test to avoid blocking calls to the package cache -#[test] -fn test_no_color() { - let keys = vec!["NO_COLOR", "CLICOLOR_FORCE", "CLICOLOR"]; - - for key in keys { - execute_test(key, "1"); - execute_test(key, "0"); - } -} diff --git a/tests/init_json_config.rs b/tests/init_json_config.rs new file mode 100755 index 00000000..7e6287c5 --- /dev/null +++ b/tests/init_json_config.rs @@ -0,0 +1,12 @@ +#[test] +#[cfg(all(feature = "config_parsing", feature = "json_format"))] +fn test_init_json_cfg() { + use log4rs; + use std::path::Path; + + assert!(log4rs::init_file( + Path::new("./test_cfgs/test.json"), + log4rs::config::Deserializers::default() + ) + .is_ok()); +} diff --git a/tests/init_malformed_appenders.rs b/tests/init_malformed_appenders.rs new file mode 100755 index 00000000..c6b9e36d --- /dev/null +++ b/tests/init_malformed_appenders.rs @@ -0,0 +1,14 @@ +#[test] +#[cfg(all(feature = "config_parsing", feature = "yaml_format"))] +fn test_malformed_appenders() { + use std::fs; + + let config_str = fs::read_to_string("test_cfgs/malformed_appender.yml").unwrap(); + let cfg = ::serde_yaml::from_str::(&config_str); + + assert!(cfg.is_ok()); + let cfg = cfg.unwrap(); + + let res = log4rs::config::create_raw_config(cfg); + assert!(res.is_err()); +} diff --git a/tests/init_toml_config.rs b/tests/init_toml_config.rs new file mode 100755 index 00000000..f5b576ca --- /dev/null +++ b/tests/init_toml_config.rs @@ -0,0 +1,12 @@ +#[test] +#[cfg(all(feature = "config_parsing", feature = "toml_format"))] +fn test_init_toml_cfg() { + use log4rs; + use std::path::Path; + + assert!(log4rs::init_file( + Path::new("./test_cfgs/test.toml"), + log4rs::config::Deserializers::default() + ) + .is_ok()); +} diff --git a/tests/init_yaml_config.rs b/tests/init_yaml_config.rs new file mode 100755 index 00000000..b2a5f4da --- /dev/null +++ b/tests/init_yaml_config.rs @@ -0,0 +1,12 @@ +#[test] +#[cfg(all(feature = "config_parsing", feature = "yaml_format"))] +fn test_init_yaml_cfg() { + use log4rs; + use std::path::Path; + + assert!(log4rs::init_file( + Path::new("./test_cfgs/test.yml"), + log4rs::config::Deserializers::default() + ) + .is_ok()); +}