| Crates.io | structured_persistent_logger |
| lib.rs | structured_persistent_logger |
| version | 0.1.0 |
| created_at | 2023-11-18 14:45:22.957671+00 |
| updated_at | 2023-11-18 14:45:22.957671+00 |
| description | A structured 'log' logger that allows for persistent fields |
| homepage | |
| repository | https://github.com/klaatu01/structured_persistent_logger |
| max_upload_size | |
| id | 1040547 |
| size | 7,508 |
structured_persistent_logger is a Rust crate providing a structured logging solution that is compatible with the standard log crate. It features persistent logging capabilities, allowing for the retention and structured formatting of log records.
log crate.Add structured_persistent_logger to your Cargo.toml:
[dependencies]
structured_persistent_logger = "0.1.0"
log = "0.4.0"
To use structured_persistent_logger, initialize it at the start of your application:
use structured_persistent_logger::StructuredPersistentLogger;
fn main() {
StructuredPersistentLogger::init();
add_persistent_logs! {
"key1" => json!("value1"),
"key2" => json!({"nested": "structure"})
};
log::info!("This is an info message");
// output:
// {
// "key1": "value1",
// "key2": { "nested": "structure" },
// "message": "This is an info message",
// "level": "INFO"
// }
}
You can add persistent logs that will be included in every log message:
use structured_persistent_logger::add_persistent_logs;
use serde_json::json;
fn some_function() {
add_persistent_logs! {
"key1" => json!("value1"),
"key2" => json!(123)
};
}
The logger can be configured to adjust its behavior, such as setting log levels or customizing the format of log entries.
We welcome contributions to structured_persistent_logger! Please feel free to submit pull requests or open issues to improve the library.
This crate is licensed under MIT license.