tracing-ndjson
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.
Features
- Configurable field names for
target,message,level, andtimestamp. - Configurable timestamp formats
- RFC3339 (
2023-10-08T03:30:52Z), - RFC339Nanos (
2023-10-08T03:30:52.123456789Z) - Unix timestamp (
1672535452) - UnixMills (
1672535452123)
- RFC3339 (
- Captures all span attributes and event fields in the root of the JSON object. Collisions will result in overwriting the existing field.
Limitations
- When flattening span attributes and event fields, the library will overwrite any existing fields with the same name, including the built-in fields such as
target,message,level,timestamp,file, andline. - Non-determistic ordering of fields in the JSON object. (JSON objects are unordered)
- Currently only logs to stdout. (PRs welcome!)
Usage
Add this to your Cargo.toml:
[]
= "0.1"
= "0.2"
use *;
Examples
See the examples directory for more examples.
License
Licensed under MIT license