Expand description
§wide-log
A high-speed wide-event logging system for Rust. A single structured event accumulates fields throughout a request/task lifecycle and is emitted as one JSON line on completion.
§Quick Start
The wide_log! macro takes a JSON object literal and generates the key
enum, Key trait impl, thread-local storage, guard builder, current()
accessor, scope() / scope_default() async functions (behind the
tokio feature), WideLogLayer tower middleware (behind the tokio
feature), and all logging macros (wl_set!, wl_inc!, info!, etc.) in
one invocation.
use wide_log::wide_log;
wide_log!({
"service": {
"name": null,
"version": "1.0.0",
},
"requests": counter!,
});
let _guard = WideLogGuard::builder().build();
wl_set!("service.name", "example-service");
wl_inc!("requests");
info!("request received");
// _guard drops → duration.total_ms set, timestamp set,
// event emitted as a JSON line to non-blocking stdout.§Auto-Added Keys
"log"— log entries frominfo!(),warn!(), etc. Handled internally; never declared by the user."duration"— elapsed time in ms. Auto-added as"duration": { "total_ms": duration! }if not declared."event"— event metadata. Auto-added as"event": { "timestamp": null, "id": null }if not declared. Thetimestampis set to an RFC 3339 string on drop. Theidis set to a ULID string (or UUIDv4 with theuuidfeature) onbuild().
§Customizable Key Strings
All 8 built-in key strings can be renamed using an optional bracketed override list before the JSON object:
use wide_log::wide_log;
wide_log!([
Event.Id => "correlation_id",
Log.Level => "severity",
], {
"service": { "name": null },
"requests": counter!,
});See the README for the full list of override paths.
§Builder Pattern
Use WideLogGuard::builder() to construct a guard. The builder allows
specifying a custom timezone, ID generator, and emit function:
use wide_log::wide_log;
wide_log!({ "service": { "name": null }, "requests": counter! });
// Default: UTC timezone, ULID ID, non-blocking stdout emit
let _guard = WideLogGuard::builder().build();
// Custom timezone
use chrono_tz::Tz;
let _guard = WideLogGuard::builder()
.with_timezone(Tz::America__New_York)
.build();
// Custom ID generator
let _guard = WideLogGuard::builder()
.with_id(|| "my-custom-id".to_string())
.build();
// Custom emit function
let _guard = WideLogGuard::builder()
.with_emit(|ev| { println!("{}", ev.to_json().unwrap()); })
.build();UUIDv4 IDs are available with the uuid feature: WideLogGuard::builder().with_uuid().build().
§info! Shadowing
The generated info!, warn!, error!, debug!, trace! macros shadow
tracing::info! etc. when both are in scope. To call the real tracing
macros, use the fully qualified path: ::tracing::info!(...). (The default
default_emit no longer routes through tracing; it writes the
serialized JSON line directly to non-blocking stdout via
stdout_emit::submit.)
§Features
tokio— enables async support:scope(),scope_default(),WideLogLayertower middleware, andtokio::task_local!storage.uuid— enablesWideLogGuardBuilder::with_uuid()for UUIDv4 ID generation instead of the default ULID.
Modules§
- __
re_ exports_ core - stdout_
emit - Non-blocking stdout emit for wide events.
Macros§
- wide_
log - The
wide_log!proc-macro. See the crate-level documentation for syntax and usage details.
Structs§
- Context
Cell - A thread-local cell storing a raw pointer to the current wide event.
- Scoped
Guard - RAII guard that owns a
WideEventand emits it on drop. - Wide
Event - A wide event — a structured log record that accumulates fields throughout a request/task lifecycle and is emitted as a single JSON line on completion.
Enums§
Traits§
- Key
- Trait for wide-event keys.