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 build failure when using target features #46

Merged
merged 3 commits into from
Sep 23, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "2.0.0"
version = "2.1.0"
edition = "2021"
authors = ["baoyachi <liaoymxsdl@gmail.com>"]
description = "A simple log. It's really simple use"
Expand All @@ -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]
Expand Down
22 changes: 2 additions & 20 deletions src/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -241,10 +241,10 @@ pub fn get_log_conf() -> SimpleResult<LogConfig> {
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<TargetLevel>);
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub struct LogConfig {
Expand Down Expand Up @@ -278,24 +278,6 @@ impl Default for LogConfig {
}
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct TargetLevel {
name: String,
level: LevelFilter,
}

impl<S> From<(S, LevelFilter)> for TargetLevel
where
S: AsRef<str>,
{
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()
Expand Down
5 changes: 2 additions & 3 deletions src/level.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::inner::InnerLevel;
use crate::InnerLevel;
use core::fmt;
use log::{Level, LevelFilter};
pub use parser::*;
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};
Expand Down
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = Result<T, String>;
pub(crate) type InnerLevel = (LevelFilter, Vec<TargetLevel>);

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct TargetLevel {
name: String,
level: LevelFilter,
}

impl<S> From<(S, LevelFilter)> for TargetLevel
where
S: AsRef<str>,
{
fn from(value: (S, LevelFilter)) -> Self {
Self {
name: value.0.as_ref().to_string(),
level: value.1,
}
}
}
2 changes: 1 addition & 1 deletion src/out_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
}
}

pub fn deserialize_out_kind<'de, D>(deserializer: D) -> Result<Vec<OutKind>, D::Error>
pub(crate) fn deserialize_out_kind<'de, D>(deserializer: D) -> Result<Vec<OutKind>, D::Error>

Check warning on line 77 in src/out_kind.rs

View workflow job for this annotation

GitHub Actions / compile

function `deserialize_out_kind` is never used

Check warning on line 77 in src/out_kind.rs

View workflow job for this annotation

GitHub Actions / compile

function `deserialize_out_kind` is never used
where
D: Deserializer<'de>,
{
Expand Down
Loading