pub struct LogRecords(/* private fields */);Expand description
A set of records that can be attached to a logging scope.
LogRecords represents a set of key-value pairs that can be
added to log messages when the log context scope is active.
§Ordering
The order in which records appear is not guaranteed. Do not rely on any specific ordering of keys.
Implementations§
Source§impl LogRecords
impl LogRecords
Sourcepub fn with_record(
self,
key: impl Into<Cow<'static, str>>,
value: impl Into<LogValue>,
) -> Self
pub fn with_record( self, key: impl Into<Cow<'static, str>>, value: impl Into<LogValue>, ) -> Self
Inserts a key-value record into this collection, returning the collection for chained calls.
This method takes ownership of self, so it can be used as part of a
builder-style chain:
§Examples
use context_logger::LogRecords;
let records = LogRecords::new()
.with_record("user_id", "user-123")
.with_record("request_id", 42);Sourcepub fn insert(
&mut self,
key: impl Into<Cow<'static, str>>,
value: impl Into<LogValue>,
) -> &mut Self
pub fn insert( &mut self, key: impl Into<Cow<'static, str>>, value: impl Into<LogValue>, ) -> &mut Self
Inserts a key-value record into this collection.
Unlike with_record, this method borrows self and
returns a mutable reference, allowing it to be used when chaining with other methods
that require borrowing.
§Examples
use context_logger::LogRecords;
let mut records = LogRecords::new();
records
.insert("user_id", "user-123")
.insert("request_id", 42);Sourcepub fn merge_with(
&mut self,
other: impl IntoIterator<Item = (Cow<'static, str>, LogValue)>,
) -> &mut Self
pub fn merge_with( &mut self, other: impl IntoIterator<Item = (Cow<'static, str>, LogValue)>, ) -> &mut Self
Merges this collection with the records from another collection.
This method borrows self and returns a mutable reference, allowing it
to be used when chaining with other methods that require borrowing.
§Merging policy
Keys in this collection with duplicate names will be overwritten by keys from the provided collection. The order of keys in the resulting collection is undefined.
§Examples
use context_logger::LogRecords;
let mut records = LogRecords::new();
records
.insert("user_id", "Alice")
.merge_with(other_records)
.insert("request_id", 42);Trait Implementations§
Source§impl Clone for LogRecords
impl Clone for LogRecords
Source§fn clone(&self) -> LogRecords
fn clone(&self) -> LogRecords
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LogRecords
impl Debug for LogRecords
Source§impl Default for LogRecords
impl Default for LogRecords
Source§fn default() -> LogRecords
fn default() -> LogRecords
Source§impl Extend<(Cow<'static, str>, LogValue)> for LogRecords
impl Extend<(Cow<'static, str>, LogValue)> for LogRecords
Source§fn extend<I: IntoIterator<Item = (Cow<'static, str>, LogValue)>>(
&mut self,
iter: I,
)
fn extend<I: IntoIterator<Item = (Cow<'static, str>, LogValue)>>( &mut self, iter: I, )
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)