structured-logger

A logging implementation for the log crate that logs structured values as JSON (CBOR, or any other) into a file, stderr, stdout, or any other.
Inspired by std-logger.
Usage
See the API documentation for more.
Example
use serde::Serialize;
use std::io::stdout;
use structured_logger::{json::new_json_writer, unix_ms, Logger};
fn main() {
Logger::new()
.with_target_writer("request", new_json_writer(stdout()))
.init();
let kv = ContextLog {
uid: "user123".to_string(),
action: "upate_book".to_string(),
};
log::info!("hello world");
log::info!(target: "request",
method = "GET",
path = "/hello",
status = 200_u16,
start = unix_ms(),
elapsed = 10_u64,
kv = log::as_serde!(kv);
"",
);
}
#[derive(Serialize)]
struct ContextLog {
uid: String,
action: String,
}
License
Copyright © 2023-present IO Rust.
ldclabs/cose is licensed under the MIT License. See LICENSE for the full license text.