Skip to main content

wide_log

Macro wide_log 

Source
wide_log!() { /* proc-macro */ }
Expand description

The wide_log! proc-macro. See the crate-level documentation for syntax and usage details.

Takes a JSON object literal as its only parameter. The JSON structure defines all keys, their nesting/paths, default values, and which keys are counters or durations. The macro generates:

  • The EventKey enum (#[repr(u8)], one variant per unique JSON key)
  • The Key trait impl (as_str, MAX_KEYS, as_index, DURATION_PATH, TIMESTAMP_PATH, ID_PATH)
  • __wl_resolve_path — compile-time path resolution function
  • Thread-local storage (CURRENT_EVENT: ContextCell<WideEvent<EventKey>>)
  • default_emit — serializes via sonic_rs and writes the JSON line to non-blocking stdout via stdout_emit::submit
  • WideLogGuardBuilder — builder for constructing guards with timezone, ID generator, and emit function
  • WideLogGuard — guard type (constructed via builder().build())
  • current() — returns the innermost active event
  • scope() / scope_default() (behind tokio feature)
  • WideLogLayer tower middleware (behind tokio feature)
  • All logging macros: wl_set!, wl_inc!, wl_dec!, wl_add!, wl_null!, info!, warn!, error!, debug!, trace!

§Value Markers

MarkerMeaning
duration!Duration leaf; set to elapsed ms on drop
counter!Incrementable counter; init to 0 (absent)
nullNo default value; set via wl_set!
"literal"String default; set on guard creation
123Numeric default; set on guard creation
true/falseBoolean default; set on guard creation

§Duration Auto-Add Rules

If no "duration" key is declared, the macro adds "duration": { "total_ms": duration! } automatically. See the README for the full duration resolution table.

§Event Auto-Add Rules

If no "event" key is declared, the macro adds "event": { "timestamp": null, "id": null } automatically. The timestamp is set to an RFC 3339 string on drop. The id is set to a ULID string (or UUIDv4 with the uuid feature) on build().