diff --git a/src/encode/json.rs b/src/encode/json.rs index f1592b6f..53efae9c 100644 --- a/src/encode/json.rs +++ b/src/encode/json.rs @@ -24,6 +24,11 @@ //! } //! } //! ``` +//! If the `log_kv` feature is enabled, an additional `attributes` field will +//! contain a map of the record's [log::kv][log_kv] structured logging +//! attributes. +//! +//! [log_kv]: https://docs.rs/log/latest/log/kv/index.html use chrono::{ format::{DelayedFormat, Fixed, Item}, @@ -173,9 +178,7 @@ mod kv { pub(crate) type Map = BTreeMap; - pub(crate) fn get_attributes( - source: &dyn log::kv::Source, - ) -> anyhow::Result { + pub(crate) fn get_attributes(source: &dyn log::kv::Source) -> anyhow::Result { struct Visitor { inner: Map, } diff --git a/src/encode/pattern/mod.rs b/src/encode/pattern/mod.rs index b5a8f741..9fad0e00 100644 --- a/src/encode/pattern/mod.rs +++ b/src/encode/pattern/mod.rs @@ -73,6 +73,14 @@ //! defaults to the empty string. //! * `{X(user_id)}` - `123e4567-e89b-12d3-a456-426655440000` //! * `{X(nonexistent_key)(no mapping)}` - `no mapping` +//! * `K`, `key_value` - A value from a [log::kv][log_kv] structured logging +//! record attributes. The first argument specifies the key, and the second +//! argument specifies the default value if the key is not present in the +//! log record's attributes. The second argument is optional, and defaults +//! to the empty string. This formatter requires the `log_kv` feature to be +//! enabled. +//! * `{K(user_id)}` - `123e4567-e89b-12d3-a456-426655440000` +//! * `{K(nonexistent_key)(no mapping)}` - `no mapping` //! * An "unnamed" formatter simply formats its argument, applying the format //! specification. //! * `{({l} {m})}` - `INFO hello` @@ -120,6 +128,7 @@ //! level `DEBUG` will be truncated to `DEBUG hello, wo`. //! //! [MDC]: https://crates.io/crates/log-mdc +//! [log_kv]: https://docs.rs/log/latest/log/kv/index.html use chrono::{Local, Utc}; use derivative::Derivative;