Skip to content

Commit

Permalink
stabilize the kv features
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Feb 16, 2024
1 parent a6c4095 commit 52460f9
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 122 deletions.
36 changes: 19 additions & 17 deletions .github/workflows/main.yml
Expand Up @@ -44,10 +44,10 @@ jobs:
- run: cargo test --verbose --all-features
- run: cargo test --verbose --features serde
- run: cargo test --verbose --features std
- run: cargo test --verbose --features kv_unstable
- run: cargo test --verbose --features kv_unstable_sval
- run: cargo test --verbose --features kv_unstable_serde
- run: cargo test --verbose --features "kv_unstable kv_unstable_std kv_unstable_sval kv_unstable_serde"
- run: cargo test --verbose --features kv
- run: cargo test --verbose --features kv_sval
- run: cargo test --verbose --features kv_serde
- run: cargo test --verbose --features "kv kv_std kv_sval kv_serde"
- run: cargo run --verbose --manifest-path test_max_level_features/Cargo.toml
- run: cargo run --verbose --manifest-path test_max_level_features/Cargo.toml --release

Expand Down Expand Up @@ -103,12 +103,12 @@ jobs:
run: |
rustup update nightly --no-self-update
rustup default nightly
- run: cargo build --verbose -Z avoid-dev-deps --features kv_unstable
- run: cargo build --verbose -Z avoid-dev-deps --features "kv_unstable std"
- run: cargo build --verbose -Z avoid-dev-deps --features "kv_unstable kv_unstable_sval"
- run: cargo build --verbose -Z avoid-dev-deps --features "kv_unstable kv_unstable_serde"
- run: cargo build --verbose -Z avoid-dev-deps --features "kv_unstable kv_unstable_std"
- run: cargo build --verbose -Z avoid-dev-deps --features "kv_unstable kv_unstable_sval kv_unstable_serde"
- run: cargo build --verbose -Z avoid-dev-deps --features kv
- run: cargo build --verbose -Z avoid-dev-deps --features "kv std"
- run: cargo build --verbose -Z avoid-dev-deps --features "kv kv_sval"
- run: cargo build --verbose -Z avoid-dev-deps --features "kv kv_serde"
- run: cargo build --verbose -Z avoid-dev-deps --features "kv kv_std"
- run: cargo build --verbose -Z avoid-dev-deps --features "kv kv_sval kv_serde"

minimalv:
name: Minimal versions
Expand All @@ -119,12 +119,12 @@ jobs:
run: |
rustup update nightly --no-self-update
rustup default nightly
- run: cargo build --verbose -Z minimal-versions --features kv_unstable
- run: cargo build --verbose -Z minimal-versions --features "kv_unstable std"
- run: cargo build --verbose -Z minimal-versions --features "kv_unstable kv_unstable_sval"
- run: cargo build --verbose -Z minimal-versions --features "kv_unstable kv_unstable_serde"
- run: cargo build --verbose -Z minimal-versions --features "kv_unstable kv_unstable_std"
- run: cargo build --verbose -Z minimal-versions --features "kv_unstable kv_unstable_sval kv_unstable_serde"
- run: cargo build --verbose -Z minimal-versions --features kv
- run: cargo build --verbose -Z minimal-versions --features "kv std"
- run: cargo build --verbose -Z minimal-versions --features "kv kv_sval"
- run: cargo build --verbose -Z minimal-versions --features "kv kv_serde"
- run: cargo build --verbose -Z minimal-versions --features "kv kv_std"
- run: cargo build --verbose -Z minimal-versions --features "kv kv_sval kv_serde"

msrv:
name: MSRV
Expand All @@ -135,7 +135,9 @@ jobs:
run: |
rustup update 1.60.0 --no-self-update
rustup default 1.60.0
- run: cargo test --verbose --manifest-path tests/Cargo.toml
- run: |
cargo test --verbose --manifest-path tests/Cargo.toml
cargo test --verbose --manifest-path tests/Cargo.toml --features kv
embedded:
name: Embedded
Expand Down
18 changes: 11 additions & 7 deletions Cargo.toml
Expand Up @@ -17,7 +17,7 @@ rust-version = "1.60.0"
edition = "2021"

[package.metadata.docs.rs]
features = ["std", "serde", "kv_unstable_std", "kv_unstable_sval", "kv_unstable_serde"]
features = ["std", "serde", "kv_std", "kv_sval", "kv_serde"]

[[test]]
name = "filters"
Expand Down Expand Up @@ -46,12 +46,16 @@ release_max_level_trace = []

std = []

# requires the latest stable
# this will have a tighter MSRV before stabilization
kv_unstable = []
kv_unstable_sval = ["kv_unstable", "value-bag/sval", "sval", "sval_ref"]
kv_unstable_std = ["std", "kv_unstable", "value-bag/error"]
kv_unstable_serde = ["kv_unstable_std", "value-bag/serde", "serde"]
kv = []
kv_sval = ["kv", "value-bag/sval", "sval", "sval_ref"]
kv_std = ["std", "kv", "value-bag/error"]
kv_serde = ["kv_std", "value-bag/serde", "serde"]

# Legacy: use `kv_*` instead
kv_unstable = ["kv"]
kv_unstable_sval = ["kv_sval"]
kv_unstable_std = ["kv_std"]
kv_unstable_serde = ["kv_serde"]

[dependencies]
serde = { version = "1.0", optional = true, default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -100,7 +100,7 @@ The executable itself may use the `log` crate to log as well.

## Structured logging

If you enable the `kv_unstable` feature, you can associate structured data with your log records:
If you enable the `kv` feature, you can associate structured data with your log records:

```rust
use log::{info, trace, warn};
Expand Down
2 changes: 1 addition & 1 deletion benches/value.rs
@@ -1,4 +1,4 @@
#![cfg(feature = "kv_unstable")]
#![cfg(feature = "kv")]
#![feature(test)]

use log::kv::Value;
Expand Down
20 changes: 9 additions & 11 deletions src/__private_api.rs
Expand Up @@ -5,7 +5,7 @@ use crate::{Level, Metadata, Record};
use std::fmt::Arguments;
pub use std::{file, format_args, line, module_path, stringify};

#[cfg(not(feature = "kv_unstable"))]
#[cfg(not(feature = "kv"))]
pub type Value<'a> = &'a str;

mod sealed {
Expand Down Expand Up @@ -40,11 +40,9 @@ fn log_impl(
line: u32,
kvs: Option<&[(&str, Value)]>,
) {
#[cfg(not(feature = "kv_unstable"))]
#[cfg(not(feature = "kv"))]
if kvs.is_some() {
panic!(
"key-value support is experimental and must be enabled using the `kv_unstable` feature"
)
panic!("key-value support is experimental and must be enabled using the `kv` feature")
}

let mut builder = Record::builder();
Expand All @@ -57,7 +55,7 @@ fn log_impl(
.file_static(Some(file))
.line(Some(line));

#[cfg(feature = "kv_unstable")]
#[cfg(feature = "kv")]
builder.key_values(&kvs);

crate::logger().log(&builder.build());
Expand Down Expand Up @@ -85,7 +83,7 @@ pub fn enabled(level: Level, target: &str) -> bool {
crate::logger().enabled(&Metadata::builder().level(level).target(target).build())
}

#[cfg(feature = "kv_unstable")]
#[cfg(feature = "kv")]
mod kv_support {
use crate::kv;

Expand All @@ -107,21 +105,21 @@ mod kv_support {
Value::from_display(v)
}

#[cfg(feature = "kv_unstable_std")]
#[cfg(feature = "kv_std")]
pub fn capture_error<'a>(v: &'a (dyn std::error::Error + 'static)) -> Value<'a> {
Value::from_dyn_error(v)
}

#[cfg(feature = "kv_unstable_sval")]
#[cfg(feature = "kv_sval")]
pub fn capture_sval<'a, V: sval::Value + ?Sized>(v: &'a &'a V) -> Value<'a> {
Value::from_sval(v)
}

#[cfg(feature = "kv_unstable_serde")]
#[cfg(feature = "kv_serde")]
pub fn capture_serde<'a, V: serde::Serialize + ?Sized>(v: &'a &'a V) -> Value<'a> {
Value::from_serde(v)
}
}

#[cfg(feature = "kv_unstable")]
#[cfg(feature = "kv")]
pub use self::kv_support::*;
4 changes: 2 additions & 2 deletions src/kv/error.rs
Expand Up @@ -37,9 +37,9 @@ impl Error {
pub(super) fn into_value(self) -> crate::kv::value::inner::Error {
match self.inner {
Inner::Value(err) => err,
#[cfg(feature = "kv_unstable_std")]
#[cfg(feature = "kv_std")]
_ => crate::kv::value::inner::Error::boxed(self),
#[cfg(not(feature = "kv_unstable_std"))]
#[cfg(not(feature = "kv_std"))]
_ => crate::kv::value::inner::Error::msg("error inspecting a value"),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/kv/key.rs
Expand Up @@ -93,7 +93,7 @@ mod std_support {
}
}

#[cfg(feature = "kv_unstable_sval")]
#[cfg(feature = "kv_sval")]
mod sval_support {
use super::*;

Expand All @@ -116,7 +116,7 @@ mod sval_support {
}
}

#[cfg(feature = "kv_unstable_serde")]
#[cfg(feature = "kv_serde")]
mod serde_support {
use super::*;

Expand Down
16 changes: 6 additions & 10 deletions src/kv/mod.rs
@@ -1,15 +1,11 @@
//! **UNSTABLE:** Structured logging.
//! Structured logging.
//!
//! This module is unstable and breaking changes may be made
//! at any time. See [the tracking issue](https://github.com/rust-lang-nursery/log/issues/328)
//! for more details.
//!
//! Add the `kv_unstable` feature to your `Cargo.toml` to enable
//! Add the `kv` feature to your `Cargo.toml` to enable
//! this module:
//!
//! ```toml
//! [dependencies.log]
//! features = ["kv_unstable"]
//! features = ["kv"]
//! ```
//!
//! # Structured logging in `log`
Expand Down Expand Up @@ -48,9 +44,9 @@
//! - `:debug` will capture the value using `Debug`.
//! - `:%` will capture the value using `Display`.
//! - `:display` will capture the value using `Display`.
//! - `:error` will capture the value using `std::error::Error` (requires the `kv_unstable_std` feature).
//! - `:sval` will capture the value using `sval::Value` (requires the `kv_unstable_sval` feature).
//! - `:serde` will capture the value using `serde::Serialize` (requires the `kv_unstable_serde` feature).
//! - `:error` will capture the value using `std::error::Error` (requires the `kv_std` feature).
//! - `:sval` will capture the value using `sval::Value` (requires the `kv_sval` feature).
//! - `:serde` will capture the value using `serde::Serialize` (requires the `kv_serde` feature).
//!
//! ## Working with key-values on log records
//!
Expand Down

0 comments on commit 52460f9

Please sign in to comment.