Expand description
§Serializable Log Record
This crate provides a SerializableLogRecord struct which is a custom representation of the log::Record struct from the log crate.
The log::Record struct is not directly serializable due to the use of fmt::Arguments.
The SerializableLogRecord struct solves this problem by providing a serializable version of log::Record.
§Usage
Convert a log::Record to a SerializableLogRecord using the ::from method:
use serializable_log_record::SerializableLogRecord;
//let record: log::Record = ...;
let serializable_record = SerializableLogRecord::from(&record);Serde’s Serialize and Deserialize traits are implemented for SerializableLogRecord if the serde feature is enabled.
The feature bincode2 is also available which implements bincode::Encode and bincode::Decode from bincode version 2 for SerializableLogRecord.
To convert a SerializableLogRecord back into a log::Record use the into_log_record macro. The result of this macro has to be passed
directly into a call to the log method of any log::Log implementation. It cannot be stored in an intermediate variable or alike due to
the extremely restrictive lifetime of the args field of log::Record.
let mut builder = log::Record::builder();
any_logger.log(&serializable_log_record::into_log_record!(builder, serializable_record));Macros§
- into_
log_ record - This macro converts a
SerializableLogRecordinto alog::Recordwhich is to be passed immediately into a call to thelogmethod of anylog::Logimplementation.
Structs§
- Serializable
LogRecord - A custom representation of the
log::Recordstruct which is unfortunately not directly serializable (due to the use offmt::Arguments).