pub struct LogValue(/* private fields */);Expand description
Represents a value that can be stored in a log field.
The LogValue type is a flexible container designed to hold various kinds of data
that can be associated with a log entry. It supports primitive types, strings, and
more complex types such as those implementing std::fmt::Debug, std::fmt::Display,
std::error::Error, or serde::Serialize.
This allows for rich and structured logging, enabling developers to attach meaningful context to log messages.
§Examples
use context_logger::LogValue;
let value = LogValue::display("example string");
let number = LogValue::from(42);
let debug_value = LogValue::debug(vec![1, 2, 3]);Implementations§
Source§impl LogValue
impl LogValue
Sourcepub fn serde<S>(value: S) -> Self
pub fn serde<S>(value: S) -> Self
Creates a log value from a serde::Serialize.
Sourcepub fn display<T>(value: T) -> Self
pub fn display<T>(value: T) -> Self
Creates a log value from a std::fmt::Display.
Sourcepub fn debug<T>(value: T) -> Self
pub fn debug<T>(value: T) -> Self
Creates a log value from a std::fmt::Debug.
Sourcepub fn error<T>(value: T) -> Self
pub fn error<T>(value: T) -> Self
Creates a log value from a std::error::Error.
Sourcepub fn as_log_value(&self) -> Value<'_>
pub fn as_log_value(&self) -> Value<'_>
Converts the log value to a value compatible with the log crate.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for LogValue
impl !UnwindSafe for LogValue
impl Freeze for LogValue
impl Send for LogValue
impl Sync for LogValue
impl Unpin for LogValue
impl UnsafeUnpin for LogValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more