#[non_exhaustive]pub struct Record<'a> {
pub metadata: Metadata<'a>,
pub message: &'a str,
pub fields: &'a [Field<'a>],
pub context: &'a [Field<'a>],
}Expand description
A complete, immutable log record.
Records borrow their data; the lifetime parameter is the shortest
of the borrows. A crate::Sink receives a &Record and must not
retain it past the call.
fields holds the per-call fields and context holds ambient
fields (logger defaults and thread-local context). When a record is
produced by a crate::Logger, keys are unique across both slices:
a call field shadows a context field with the same key, and a
context field shadows a default field. Hand-built records are
rendered exactly as given.
The struct is #[non_exhaustive]; construct it with
Record::new or Record::with_context.
§Examples
use log_io::{Field, Level, Metadata, Record};
let fields = [Field::new("port", 80_u16)];
let ctx = [Field::new("trace_id", "abc")];
let record = Record::with_context(Metadata::new(Level::Info, "app"), "up", &fields, &ctx);
let keys: Vec<&str> = record.all_fields().map(|f| f.key).collect();
assert_eq!(keys, ["trace_id", "port"]);Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.metadata: Metadata<'a>Static origin and severity information.
message: &'a strFree-form message.
fields: &'a [Field<'a>]Borrowed per-call structured fields. May be empty.
context: &'a [Field<'a>]Borrowed context fields (defaults and thread-local context).
May be empty. Kept apart from fields so formatters can label
or order them differently.
Implementations§
Source§impl<'a> Record<'a>
impl<'a> Record<'a>
Sourcepub const fn new(
metadata: Metadata<'a>,
message: &'a str,
fields: &'a [Field<'a>],
) -> Self
pub const fn new( metadata: Metadata<'a>, message: &'a str, fields: &'a [Field<'a>], ) -> Self
Build a record with no context fields.
Sourcepub const fn with_context(
metadata: Metadata<'a>,
message: &'a str,
fields: &'a [Field<'a>],
context: &'a [Field<'a>],
) -> Self
pub const fn with_context( metadata: Metadata<'a>, message: &'a str, fields: &'a [Field<'a>], context: &'a [Field<'a>], ) -> Self
Build a record with explicit context fields.
Sourcepub fn all_fields(&self) -> impl Iterator<Item = &Field<'a>>
pub fn all_fields(&self) -> impl Iterator<Item = &Field<'a>>
Iterate over context fields followed by per-call fields, the order every built-in formatter uses.