diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 55a4169..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 @@ -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: 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>, {