From e72307caf4ac1cd04bda63739770afd78a30da96 Mon Sep 17 00:00:00 2001 From: baoyachi Date: Fri, 20 Sep 2024 19:37:45 +0800 Subject: [PATCH 1/3] update github action check --- .github/workflows/rust.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 55a4169..8db8ae1 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -33,7 +33,9 @@ jobs: - name: Set up Rust uses: hecrj/setup-rust-action@v2 - uses: actions/checkout@master - - run: cargo check --all-targets --all-features + - run: | + cargo check --all-targets --all-features + cargo check --no-default-features test: strategy: From 07d90f9f825ce16a335882fa90ba693c5d1fd5b7 Mon Sep 17 00:00:00 2001 From: baoyachi Date: Mon, 23 Sep 2024 10:27:03 +0800 Subject: [PATCH 2/3] Fix the issue of compilation failure when using target features --- Cargo.toml | 6 +++--- src/inner.rs | 22 ++-------------------- src/level.rs | 5 ++--- src/lib.rs | 21 +++++++++++++++++++++ src/out_kind.rs | 2 +- 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index efd4ff2..279f049 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace.package] -version = "2.0.0" +version = "2.1.0" edition = "2021" authors = ["baoyachi "] description = "A simple log. It's really simple use" @@ -26,10 +26,10 @@ license.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -log = "0.4.11" +log = { version = "0.4.11", features = ["serde", "std"] } log4rs = { version = "1.1.1", default-features = false, features = ["all_components", "humantime", "serde", "serde-value", "yaml_format", "gzip"], optional = true } once_cell = { version = "1.15.0", default-features = false, optional = true } -serde = { version = "1.0.145", default-features = false, features = ["derive"] } +serde = { version = "1.0.145", features = ["derive"] } winnow = "0.6.18" [dependencies.simple-log-derive] diff --git a/src/inner.rs b/src/inner.rs index c892387..99016c6 100644 --- a/src/inner.rs +++ b/src/inner.rs @@ -87,7 +87,7 @@ use crate::level::{parse_level, LevelInto}; use crate::out_kind::OutKind; -use crate::SimpleResult; +use crate::{InnerLevel, SimpleResult}; use log::LevelFilter; use log4rs::append::console::ConsoleAppender; use log4rs::append::rolling_file::policy::compound::roll::fixed_window::FixedWindowRoller; @@ -241,10 +241,10 @@ pub fn get_log_conf() -> SimpleResult { let config = log_conf.lock().unwrap().log_config.clone(); Ok(config) } + use crate::level::deserialize_level; use crate::out_kind::deserialize_out_kind; -pub(crate) type InnerLevel = (LevelFilter, Vec); #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub struct LogConfig { @@ -278,24 +278,6 @@ impl Default for LogConfig { } } -#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] -pub struct TargetLevel { - name: String, - level: LevelFilter, -} - -impl From<(S, LevelFilter)> for TargetLevel -where - S: AsRef, -{ - fn from(value: (S, LevelFilter)) -> Self { - Self { - name: value.0.as_ref().to_string(), - level: value.1, - } - } -} - impl LogConfig { fn default_basename(&self) -> String { let arg0 = std::env::args() diff --git a/src/level.rs b/src/level.rs index a92540a..6bcb7c1 100644 --- a/src/level.rs +++ b/src/level.rs @@ -1,4 +1,4 @@ -use crate::inner::InnerLevel; +use crate::InnerLevel; use core::fmt; use log::{Level, LevelFilter}; pub use parser::*; @@ -6,8 +6,7 @@ use serde::de::DeserializeSeed; use serde::{de, Deserializer}; pub(crate) mod parser { - use crate::inner::InnerLevel; - use crate::TargetLevel; + use crate::{InnerLevel, TargetLevel}; use log::LevelFilter; use std::str::FromStr; use winnow::ascii::{alpha1, multispace0}; diff --git a/src/lib.rs b/src/lib.rs index 209d29d..8b9f1a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,28 @@ pub use inner::*; pub use log::Level; pub use log::LevelFilter; +use serde::{Deserialize, Serialize}; + #[cfg(feature = "target")] pub use simple_log_derive::*; pub type SimpleResult = Result; +pub(crate) type InnerLevel = (LevelFilter, Vec); + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] +pub struct TargetLevel { + name: String, + level: LevelFilter, +} + +impl From<(S, LevelFilter)> for TargetLevel +where + S: AsRef, +{ + fn from(value: (S, LevelFilter)) -> Self { + Self { + name: value.0.as_ref().to_string(), + level: value.1, + } + } +} diff --git a/src/out_kind.rs b/src/out_kind.rs index b417a59..3ea2df4 100644 --- a/src/out_kind.rs +++ b/src/out_kind.rs @@ -74,7 +74,7 @@ impl<'de> de::Visitor<'de> for KindSerde { } } -pub fn deserialize_out_kind<'de, D>(deserializer: D) -> Result, D::Error> +pub(crate) fn deserialize_out_kind<'de, D>(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, { From 9968d2cd365442441b3c5a702c0ea15cb904a214 Mon Sep 17 00:00:00 2001 From: baoyachi Date: Mon, 23 Sep 2024 10:31:02 +0800 Subject: [PATCH 3/3] Fix github action ci --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8db8ae1..835ce82 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -15,7 +15,7 @@ jobs: # it's an unstable feature. rust-version: nightly - uses: actions/checkout@v4 - - run: cargo +nightly fmt -- --check --config-path <(echo 'license_template_path = "HEADER"') + - run: cargo +nightly fmt -- --check lint: runs-on: ubuntu-latest