From 1ece5bcec7656307bc3ab1c00a5ad195f85076f3 Mon Sep 17 00:00:00 2001 From: baoyachi Date: Tue, 20 Aug 2024 15:47:57 +0800 Subject: [PATCH] Add target feature example --- .github/workflows/rust.yml | 2 +- Cargo.toml | 9 +++++++-- README.md | 8 ++++---- examples/target.rs | 41 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 examples/target.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a47d9d1..55a4169 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -56,7 +56,7 @@ jobs: - name: Test run: | cargo test --all-features - cargo test --examples + cargo test --examples --all-features - name: Coverage if: matrix.rust == 'stable' run: cargo tarpaulin -o Lcov --output-dir ./coverage diff --git a/Cargo.toml b/Cargo.toml index 7ecfb22..c71ab58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace.package] -version = "1.7.0" +version = "1.7.1" edition = "2021" authors = ["baoyachi "] description = "A simple log. It's really simple use" @@ -36,7 +36,7 @@ convert_case = "0.6.0" [dependencies.simple-log-derive] path = "simple-log-derive" optional = true -version = "1.7.0" +version = "1" [dev-dependencies] serde_json = "1" @@ -49,3 +49,8 @@ members = ["./", "simple-log-derive"] [features] target = ["simple-log-derive"] + +[[example]] +name = "target" +path = "examples/target.rs" +required-features = ["target"] \ No newline at end of file diff --git a/README.md b/README.md index 57d72f8..229949e 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ A simple-log with local file or stdout write by Rust. ## Quick Use ```toml [dependencies] -simple-log = "1.5.1" +simple-log = "{latest}" ``` ```rust @@ -37,7 +37,7 @@ fn main() { ## Usage in project ```toml [dependencies] -simple-log = "1.5.1" +simple-log = "{latest}" ``` ```rust #[macro_use] @@ -66,7 +66,7 @@ fn main() -> Result<(), String> { ## Config with toml ```toml [dependencies] -simple-log = "1.5.1" +simple-log = "{latest}" toml = "0.5.7" ``` @@ -108,7 +108,7 @@ fn main() { ```toml [dependencies] -simple-log = "1.5.1" +simple-log = "{latest}" serde_json = "1" ``` diff --git a/examples/target.rs b/examples/target.rs new file mode 100644 index 0000000..21e247e --- /dev/null +++ b/examples/target.rs @@ -0,0 +1,41 @@ +//! `cargo run --example console` +//! +//! With OutPut +//! ```bash +//! 2024-08-20 15:43:09.309146000 [TRACE] [ctrl] :test target trace +//! 2024-08-20 15:43:09.309336000 [TRACE] [parser] :test target trace +//! 2024-08-20 15:43:09.309345000 [DEBUG] [target] :test target debug +//! 2024-08-20 15:43:09.309352000 [DEBUG] [ctrl] :test target debug +//! 2024-08-20 15:43:09.309358000 [DEBUG] [parser] :test target debug +//! 2024-08-20 15:43:09.309364000 [INFO] [target] :test target info +//! 2024-08-20 15:43:09.309371000 [INFO] [ctrl] :test target info +//! 2024-08-20 15:43:09.309377000 [INFO] [parser] :test target info +//! 2024-08-20 15:43:09.309383000 [WARN] [target] :test target warn +//! 2024-08-20 15:43:09.309389000 [ERROR] [target] :test target error +//! ``` + +#[macro_use] +extern crate simple_log; + +fn main() -> Result<(), String> { + simple_log::console("trace")?; + + simple_log::log_target!(ctrl); + simple_log::log_target!(parser); + + trace_ctrl!("test target trace"); + trace_parser!("test target trace"); + + debug!("test target debug"); + debug_ctrl!("test target debug"); + debug_parser!("test target debug"); + + info!("test target info"); + info_ctrl!("test target info"); + info_parser!("test target info"); + + warn!("test target warn"); + error!("test target error"); + + Ok(()) +}