Expand description
A tracing JSON layer with zero serialization framework dependencies.
Drop-in replacement for tracing-subscriber’s json feature, producing
identical output format without pulling in serde/serde_json/tracing-serde.
§Quick start
use tracing_microjson::JsonLayer;
use tracing_subscriber::prelude::*;
tracing_subscriber::registry()
.with(JsonLayer::new(std::io::stderr))
.init();§Configuration
JsonLayer uses a builder pattern. All options have sensible defaults —
only override what you need.
tracing_subscriber::registry()
.with(
JsonLayer::new(std::io::stderr)
.with_target(false)
.with_file(true)
.with_line_number(true)
.flatten_event(true)
.without_time(),
)
.init();| Method | Default | Effect |
|---|---|---|
JsonLayer::with_target | true | Include the event target (module path) |
JsonLayer::with_file | false | Include the source filename |
JsonLayer::with_line_number | false | Include the source line number |
JsonLayer::with_thread_ids | false | Include the thread ID |
JsonLayer::with_thread_names | false | Include the thread name |
JsonLayer::flatten_event | false | Flatten event fields to the top level instead of nesting under "fields" |
JsonLayer::with_timer | SystemTimestamp | Use a custom FormatTime implementation for timestamps |
JsonLayer::without_time | — | Disable timestamps entirely |
JsonLayer::with_buffer_capacity_limit | 4096 | Capacity threshold for per-thread buffer shrinking |
§Output format
Every event is written as a single JSON line. The fields present depend on the configuration above and whether the event occurs inside a span:
{"timestamp":"…","level":"INFO","fields":{"message":"hello"},"target":"my_app","span":{"name":"req"},"spans":[{"name":"req"}]}timestamp— RFC 3339 with microsecond precision in UTC by default. Customisable viawith_timeror disabled withwithout_time.level— always present (TRACE,DEBUG,INFO,WARN,ERROR).fields— event fields, nested under"fields"by default. Withflatten_event(true)they appear at the top level instead.target— module path, present whenwith_targetistrue.filename/line_number— source location, present when enabled viawith_file/with_line_number.threadId/threadName— thread info, present when enabled viawith_thread_ids/with_thread_names.span— the innermost active span (if any).spans— all active spans from root to leaf (if any).
Structs§
- Json
Layer - A
tracing_subscriber::Layerthat formats events as JSON lines. - System
Timestamp - A timestamp formatter that produces RFC 3339 timestamps with microsecond
precision in UTC (e.g.
2026-02-20T12:00:00.000000Z).
Traits§
- Format
Time - A type that can measure and format the current time.