Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ellttBen committed May 7, 2024
1 parent 2c55da1 commit 207d3be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/encode/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -173,9 +178,7 @@ mod kv {

pub(crate) type Map = BTreeMap<String, String>;

pub(crate) fn get_attributes(
source: &dyn log::kv::Source,
) -> anyhow::Result<Map> {
pub(crate) fn get_attributes(source: &dyn log::kv::Source) -> anyhow::Result<Map> {
struct Visitor {
inner: Map,
}
Expand Down
10 changes: 9 additions & 1 deletion src/encode/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -804,7 +813,6 @@ mod tests {
use std::thread;

use super::*;
use super::{Chunk, PatternEncoder};
#[cfg(feature = "simple_writer")]
use crate::encode::writer::simple::SimpleWriter;
#[cfg(feature = "simple_writer")]
Expand Down

0 comments on commit 207d3be

Please sign in to comment.