| Crates.io | tracing-ndjson |
| lib.rs | tracing-ndjson |
| version | 0.2.0 |
| created_at | 2023-10-08 03:56:39.220027+00 |
| updated_at | 2023-10-20 21:40:59.241898+00 |
| description | A customizable ndjson formatter for outputting tracing events |
| homepage | |
| repository | https://github.com/cmackenzie1/tracing-ndjson |
| max_upload_size | |
| id | 996896 |
| size | 42,777 |
A simple library for tracing in new-line delimited JSON format. This library is meant to be used with tracing as an alternative to the tracing_subscriber::fmt::json formatter.
The goal of this crate is to provide a flattend JSON event, comprising of fields from the span attributes and event fields, with customizeable field names and timestamp formats.
target, message, level, and timestamp.2023-10-08T03:30:52Z),2023-10-08T03:30:52.123456789Z)1672535452)1672535452123)target, message, level, timestamp, file, and line.Add this to your Cargo.toml:
[dependencies]
tracing = "0.1"
tracing-ndjson = "0.2"
use tracing_subscriber::prelude::*;
fn main() {
let subscriber = tracing_subscriber::registry().with(tracing_ndjson::layer());
tracing::subscriber::set_global_default(subscriber).unwrap();
tracing::info!(life = 42, "Hello, world!");
// {"level":"info","target":"default","life":42,"timestamp":"2023-10-20T21:17:49Z","message":"Hello, world!"}
let span = tracing::info_span!("hello", "request.uri" = "https://example.com");
span.in_scope(|| {
tracing::info!("Hello, world!");
// {"message":"Hello, world!","request.uri":"https://example.com","level":"info","target":"default","timestamp":"2023-10-20T21:17:49Z"}
});
}
See the examples directory for more examples.
Licensed under MIT license