serializable_log_record

Crates.ioserializable_log_record
lib.rsserializable_log_record
version0.3.2
sourcesrc
created_at2024-02-19 13:33:08.917988
updated_at2024-02-19 22:26:25.317491
descriptionConvert a log::Record to a serializable format. Not as straightforward as it sounds, because the log::Record contains a non-serializable type. This crate provides a way to deal with situation.
homepage
repositoryhttps://github.com/8192K/serializable_log_record
max_upload_size
id1145224
size21,867
(8192K)

documentation

README

serializable_log_record

Crates.io Docs MIT/APACHE-2.0

The log::Record struct is not serializable by default. This crate provides a serializable version of the log::Record struct. But most importantly, it provides a macro into_log_record which can convert the serialized record back into a regular record. This is not as straightforward as it sounds since the log::Record struct uses fmt::Arguments in one of its fields which is not serializable due to its extremely strict lifetime.

This crate is a central helper crate for the parallel_logger crate but can be used independently.

Usage

Add the dependency to your Cargo.toml:

[dependencies]
serializable_log_record = "0.3"

How to use in your application:

let record: log::Record = ...get the record from a logger or build it manually...;
let serializable_record = SerializableLogRecord::from(&record);

If you enable the serde feature, the SerializableLogRecord struct implements the Serialize and Deserialize traits.
If you enable the bincode2 feature, the SerializableLogRecord struct implements the Encode and Decode traits for bincode 2.

In order to convert the SerializableLogRecord back into a log::Record you can use the into_log_record macro:

let serializable_record = SerializableLogRecord::from(&record);
let mut builder = log::Record::builder();
logger.log(&SerializableLogRecord::into_log_record!(builder, serializable_record));

License

Licensed under either of

Commit count: 0

cargo fmt