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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*!
Structured diagnostics for Rust applications.
`emit` is a framework for adding diagnostics to your Rust applications with a simple, powerful data model and an expressive syntax inspired by [Message Templates](https://messagetemplates.org).
These are the technical API docs for `emit`. Also see [the guide](https://emit-rs.io) for a complete introduction.
## Getting started
```toml
[dependencies.emit]
version = "0.11.4"
[dependencies.emit_term]
version = "0.11.4"
```
```rust
# mod emit_term { pub fn stdout() -> impl emit::Emitter { emit::emitter::from_fn(|_| {}) } }
# #[cfg(not(feature = "std"))] fn main() {}
# #[cfg(feature = "std")]
fn main() {
let rt = emit::setup()
.emit_to(emit_term::stdout())
.init();
// Your app code goes here
greet("Rust");
rt.blocking_flush(std::time::Duration::from_secs(5));
}
#[emit::span("Greet {user}")]
fn greet(user: &str) {
emit::info!("Hello, {user}!");
}
```
The [`setup()`] function configures `emit` with an [`Emitter`] to write [`Event`]s to. The [`macro@emit`] macro emits an event, capturing any ambient state referred to in its template. The [`macro@span`] macro instruments a function, timing its execution and correlating any other events emitted within it together.
## Stable vs nightly toolchains
`emit` works on stable versions of Rust, but can provide more accurate compiler messages on nightly toolchains.
## Crate features
- `std` (default): Enable support for the standard library. Enable capturing properties as errors. Implies `alloc`.
- `alloc`: Enable APIs that require an allocator.
- `implicit_rt` (default): Enable configuring the default shared runtime and calling [`macro@emit`] and [`macro@span`] without needing to specify a runtime manually.
- `implicit_internal_rt` (default): Enable configuring the internal runtime for `emit`'s own diagnostics.
- `sval`: Enable capturing complex properties using `sval`.
- `serde`: Enable capturing complex properties using `serde`.
## Troubleshooting
Emitters write their own diagnostics to an alternative `emit` runtime, which you can configure via [`Setup::init_internal`] to debug them:
```
# mod emit_term { pub fn stdout() -> impl emit::runtime::InternalEmitter { emit::runtime::AssertInternal(emit::emitter::from_fn(|_| {})) } }
# #[cfg(not(feature = "std"))] fn main() {}
# #[cfg(feature = "std")]
fn main() {
// Configure the internal runtime before your regular setup
let internal_rt = emit::setup()
.emit_to(emit_term::stdout())
.init_internal();
let rt = emit::setup()
.emit_to(emit::emitter::from_fn(|evt| println!("{evt:#?}")))
.init();
// Your app code goes here
rt.blocking_flush(std::time::Duration::from_secs(5));
// Flush the internal runtime after your regular setup
internal_rt.blocking_flush(std::time::Duration::from_secs(5));
}
```
*/
extern crate alloc;
extern crate core;
/**
Get a [`Path`] of the executing module for use in [`Event::mdl`].
This macro uses the standard `module_path!` macro.
*/
/**
Get a [`Path`] of the package name for use in [`Event::mdl`].
This macro uses the build-time `CARGO_PKG_NAME` environment variable.
*/
pub use *;
pub use *;
pub use ;
pub use ;
/**
Get the shared emitter.
This method will use the [`Emitter`] from [`runtime::shared()`].
Calling `emitter::emit()` is different from `runtime::shared().emit()`:
1. `emitter::emit()` won't apply the filter.
2. `emitter::emit()` won't add a timestamp to events if they don't have one.
3. `emitter::emit()` won't add ambient properties.
*/
/**
Get the shared filter.
This method will use the [`Filter`] from [`runtime::shared()`].
*/
/**
Get the shared clock.
This method will use the [`Clock`] from [`runtime::shared()`].
*/
/**
Get the shared context.
This method will use the [`Ctxt`] from [`runtime::shared()`].
The returned context can be used with [`Frame`]s to manage the ambient state added to diagnostic events.
*/
/**
Get the shared random generator.
This method will use the [`Rng`] from [`runtime::shared()`].
*/
/**
Flush the runtime, ensuring all diagnostic events are fully processed.
This method will use [`runtime::shared()`].
This method forwards to [`Emitter::blocking_flush`], which has details on how the timeout is handled.
*/