[−]Trait astral::thirdparty::slog::KV
Key-value pair(s) for log events
Zero, one or more key value pairs chained together
Any logging data must implement this trait for slog to be able to use it,
although slog comes with default implementations within its macros (the
=>
and kv!
portions of the log macros).
If you don't use this trait, you must emit your structured data by specifying both key and value in each log event:
info!(logger, "my event"; "type_key" => %my_val);
If you implement this trait, that can become:
info!(logger, "my event"; my_val);
Types implementing this trait can emit multiple key-value pairs, and can customize their structured representation. The order of emitting them should be consistent with the way key-value pair hierarchy is traversed: from data most specific to the logging context to the most general one. Or in other words: from newest to oldest.
Implementers are are responsible for calling the emit_*
methods on the
Serializer
passed in, the Record
can be used to make display decisions
based on context, but for most plain-value structs you will just call
emit_*
.
Example
use slog::{KV, Record, Result, Serializer}; struct MyNewType(i64); impl KV for MyNewType { fn serialize(&self, _rec: &Record, serializer: &mut Serializer) -> Result { serializer.emit_i64("my_new_type", self.0) } }
See also Value
, which allows you to customize just
the right hand side of the =>
structure macro, and (if you have the
nested-values
feature enabled) SerdeValue
which allows emitting anything serde can emit.
Required methods
fn serialize(
&self,
record: &Record,
serializer: &mut dyn Serializer
) -> Result<(), Error>
&self,
record: &Record,
serializer: &mut dyn Serializer
) -> Result<(), Error>
Serialize self into Serializer
KV
should call respective Serializer
methods
for each key-value pair it contains.
Implementations on Foreign Types
impl<T, R> KV for (T, R) where
R: KV,
T: KV,
R: KV,
T: KV,
impl<T> KV for Arc<T> where
T: KV + ?Sized,
T: KV + ?Sized,
impl<T> KV for Box<T> where
T: KV + ?Sized,
T: KV + ?Sized,
impl<'a, T> KV for &'a T where
T: KV,
T: KV,
impl KV for ()
Loading content...
Implementors
impl KV for OwnedKVList
impl<'a> KV for BorrowedKV<'a>
impl<T> KV for OwnedKV<T> where
T: SendSyncRefUnwindSafeKV + ?Sized,
T: SendSyncRefUnwindSafeKV + ?Sized,
impl<V> KV for SingleKV<V> where
V: Value,
V: Value,