1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//! # 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!,
//! });
//!
//! # fn main() {
//! 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.
//! # wide_log::stdout_emit::flush();
//! # }
//! ```
//!
//! ## Auto-Added Keys
//!
//! - **`"log"`** — log entries from `info!()`, `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.
//! 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()`.
//!
//! ## 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!,
//! });
//! # fn main() {
//! # let _guard = WideLogGuard::builder().build();
//! # wl_inc!("requests");
//! # info!("request received");
//! # wide_log::stdout_emit::flush();
//! # }
//! ```
//!
//! 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! });
//!
//! # fn main() {
//! // 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();
//! # wide_log::stdout_emit::flush();
//! # }
//! ```
//!
//! 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`](crate::stdout_emit::submit).)
//!
//! ## Features
//!
//! - `tokio` — enables async support: `scope()`, `scope_default()`,
//! `WideLogLayer` tower middleware, and `tokio::task_local!` storage.
//! - `uuid` — enables `WideLogGuardBuilder::with_uuid()` for UUIDv4 ID
//! generation instead of the default ULID.
pub
pub
pub
pub
pub
pub
pub
pub
pub use Error;
pub use ScopedGuard;
pub use Key;
pub use Value;
pub use WideEvent;
pub use ContextCell;
/// The `wide_log!` proc-macro. See the [crate-level documentation](crate)
/// 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
///
/// | Marker | Meaning |
/// |---|---|
/// | `duration!` | Duration leaf; set to elapsed ms on drop |
/// | `counter!` | Incrementable counter; init to 0 (absent) |
/// | `null` | No default value; set via `wl_set!` |
/// | `"literal"` | String default; set on guard creation |
/// | `123` | Numeric default; set on guard creation |
/// | `true`/`false` | Boolean 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()`.
pub use wide_log;