1 | /// Constructs a new span. |
2 | /// |
3 | /// See [the top-level documentation][lib] for details on the syntax accepted by |
4 | /// this macro. |
5 | /// |
6 | /// [lib]: crate#using-the-macros |
7 | /// |
8 | /// # Examples |
9 | /// |
10 | /// Creating a new span: |
11 | /// ``` |
12 | /// # use tracing::{span, Level}; |
13 | /// # fn main() { |
14 | /// let span = span!(Level::TRACE, "my span" ); |
15 | /// let _enter = span.enter(); |
16 | /// // do work inside the span... |
17 | /// # } |
18 | /// ``` |
19 | #[macro_export ] |
20 | macro_rules! span { |
21 | (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr) => { |
22 | $crate::span!(target: $target, parent: $parent, $lvl, $name,) |
23 | }; |
24 | (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { |
25 | { |
26 | use $crate::__macro_support::Callsite as _; |
27 | static __CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! { |
28 | name: $name, |
29 | kind: $crate::metadata::Kind::SPAN, |
30 | target: $target, |
31 | level: $lvl, |
32 | fields: $($fields)* |
33 | }; |
34 | let mut interest = $crate::subscriber::Interest::never(); |
35 | if $crate::level_enabled!($lvl) |
36 | && { interest = __CALLSITE.interest(); !interest.is_never() } |
37 | && $crate::__macro_support::__is_enabled(__CALLSITE.metadata(), interest) |
38 | { |
39 | let meta = __CALLSITE.metadata(); |
40 | // span with explicit parent |
41 | $crate::Span::child_of( |
42 | $parent, |
43 | meta, |
44 | &$crate::valueset!(meta.fields(), $($fields)*), |
45 | ) |
46 | } else { |
47 | let span = $crate::__macro_support::__disabled_span(__CALLSITE.metadata()); |
48 | $crate::if_log_enabled! { $lvl, { |
49 | span.record_all(&$crate::valueset!(__CALLSITE.metadata().fields(), $($fields)*)); |
50 | }}; |
51 | span |
52 | } |
53 | } |
54 | }; |
55 | (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { |
56 | { |
57 | use $crate::__macro_support::Callsite as _; |
58 | static __CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite2! { |
59 | name: $name, |
60 | kind: $crate::metadata::Kind::SPAN, |
61 | target: $target, |
62 | level: $lvl, |
63 | fields: $($fields)* |
64 | }; |
65 | let mut interest = $crate::subscriber::Interest::never(); |
66 | if $crate::level_enabled!($lvl) |
67 | && { interest = __CALLSITE.interest(); !interest.is_never() } |
68 | && $crate::__macro_support::__is_enabled(__CALLSITE.metadata(), interest) |
69 | { |
70 | let meta = __CALLSITE.metadata(); |
71 | // span with contextual parent |
72 | $crate::Span::new( |
73 | meta, |
74 | &$crate::valueset!(meta.fields(), $($fields)*), |
75 | ) |
76 | } else { |
77 | let span = $crate::__macro_support::__disabled_span(__CALLSITE.metadata()); |
78 | $crate::if_log_enabled! { $lvl, { |
79 | span.record_all(&$crate::valueset!(__CALLSITE.metadata().fields(), $($fields)*)); |
80 | }}; |
81 | span |
82 | } |
83 | } |
84 | }; |
85 | (target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr) => { |
86 | $crate::span!(target: $target, parent: $parent, $lvl, $name,) |
87 | }; |
88 | (parent: $parent:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { |
89 | $crate::span!( |
90 | target: module_path!(), |
91 | parent: $parent, |
92 | $lvl, |
93 | $name, |
94 | $($fields)* |
95 | ) |
96 | }; |
97 | (parent: $parent:expr, $lvl:expr, $name:expr) => { |
98 | $crate::span!( |
99 | target: module_path!(), |
100 | parent: $parent, |
101 | $lvl, |
102 | $name, |
103 | ) |
104 | }; |
105 | (target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { |
106 | $crate::span!( |
107 | target: $target, |
108 | $lvl, |
109 | $name, |
110 | $($fields)* |
111 | ) |
112 | }; |
113 | (target: $target:expr, $lvl:expr, $name:expr) => { |
114 | $crate::span!(target: $target, $lvl, $name,) |
115 | }; |
116 | ($lvl:expr, $name:expr, $($fields:tt)*) => { |
117 | $crate::span!( |
118 | target: module_path!(), |
119 | $lvl, |
120 | $name, |
121 | $($fields)* |
122 | ) |
123 | }; |
124 | ($lvl:expr, $name:expr) => { |
125 | $crate::span!( |
126 | target: module_path!(), |
127 | $lvl, |
128 | $name, |
129 | ) |
130 | }; |
131 | } |
132 | |
133 | /// Constructs a span at the trace level. |
134 | /// |
135 | /// [Fields] and [attributes] are set using the same syntax as the [`span!`] |
136 | /// macro. |
137 | /// |
138 | /// See [the top-level documentation][lib] for details on the syntax accepted by |
139 | /// this macro. |
140 | /// |
141 | /// [lib]: crate#using-the-macros |
142 | /// [attributes]: crate#configuring-attributes |
143 | /// [Fields]: crate#recording-fields |
144 | /// [`span!`]: crate::span! |
145 | /// |
146 | /// # Examples |
147 | /// |
148 | /// ```rust |
149 | /// # use tracing::{trace_span, span, Level}; |
150 | /// # fn main() { |
151 | /// trace_span!("my_span" ); |
152 | /// // is equivalent to: |
153 | /// span!(Level::TRACE, "my_span" ); |
154 | /// # } |
155 | /// ``` |
156 | /// |
157 | /// ```rust |
158 | /// # use tracing::{trace_span, span, Level}; |
159 | /// # fn main() { |
160 | /// let span = trace_span!("my span" ); |
161 | /// span.in_scope(|| { |
162 | /// // do work inside the span... |
163 | /// }); |
164 | /// # } |
165 | /// ``` |
166 | #[macro_export ] |
167 | macro_rules! trace_span { |
168 | (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { |
169 | $crate::span!( |
170 | target: $target, |
171 | parent: $parent, |
172 | $crate::Level::TRACE, |
173 | $name, |
174 | $($field)* |
175 | ) |
176 | }; |
177 | (target: $target:expr, parent: $parent:expr, $name:expr) => { |
178 | $crate::trace_span!(target: $target, parent: $parent, $name,) |
179 | }; |
180 | (parent: $parent:expr, $name:expr, $($field:tt)*) => { |
181 | $crate::span!( |
182 | target: module_path!(), |
183 | parent: $parent, |
184 | $crate::Level::TRACE, |
185 | $name, |
186 | $($field)* |
187 | ) |
188 | }; |
189 | (parent: $parent:expr, $name:expr) => { |
190 | $crate::trace_span!(parent: $parent, $name,) |
191 | }; |
192 | (target: $target:expr, $name:expr, $($field:tt)*) => { |
193 | $crate::span!( |
194 | target: $target, |
195 | $crate::Level::TRACE, |
196 | $name, |
197 | $($field)* |
198 | ) |
199 | }; |
200 | (target: $target:expr, $name:expr) => { |
201 | $crate::trace_span!(target: $target, $name,) |
202 | }; |
203 | ($name:expr, $($field:tt)*) => { |
204 | $crate::span!( |
205 | target: module_path!(), |
206 | $crate::Level::TRACE, |
207 | $name, |
208 | $($field)* |
209 | ) |
210 | }; |
211 | ($name:expr) => { $crate::trace_span!($name,) }; |
212 | } |
213 | |
214 | /// Constructs a span at the debug level. |
215 | /// |
216 | /// [Fields] and [attributes] are set using the same syntax as the [`span!`] |
217 | /// macro. |
218 | /// |
219 | /// See [the top-level documentation][lib] for details on the syntax accepted by |
220 | /// this macro. |
221 | /// |
222 | /// [lib]: crate#using-the-macros |
223 | /// [attributes]: crate#configuring-attributes |
224 | /// [Fields]: crate#recording-fields |
225 | /// [`span!`]: crate::span! |
226 | /// |
227 | /// # Examples |
228 | /// |
229 | /// ```rust |
230 | /// # use tracing::{debug_span, span, Level}; |
231 | /// # fn main() { |
232 | /// debug_span!("my_span" ); |
233 | /// // is equivalent to: |
234 | /// span!(Level::DEBUG, "my_span" ); |
235 | /// # } |
236 | /// ``` |
237 | /// |
238 | /// ```rust |
239 | /// # use tracing::debug_span; |
240 | /// # fn main() { |
241 | /// let span = debug_span!("my span" ); |
242 | /// span.in_scope(|| { |
243 | /// // do work inside the span... |
244 | /// }); |
245 | /// # } |
246 | /// ``` |
247 | #[macro_export ] |
248 | macro_rules! debug_span { |
249 | (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { |
250 | $crate::span!( |
251 | target: $target, |
252 | parent: $parent, |
253 | $crate::Level::DEBUG, |
254 | $name, |
255 | $($field)* |
256 | ) |
257 | }; |
258 | (target: $target:expr, parent: $parent:expr, $name:expr) => { |
259 | $crate::debug_span!(target: $target, parent: $parent, $name,) |
260 | }; |
261 | (parent: $parent:expr, $name:expr, $($field:tt)*) => { |
262 | $crate::span!( |
263 | target: module_path!(), |
264 | parent: $parent, |
265 | $crate::Level::DEBUG, |
266 | $name, |
267 | $($field)* |
268 | ) |
269 | }; |
270 | (parent: $parent:expr, $name:expr) => { |
271 | $crate::debug_span!(parent: $parent, $name,) |
272 | }; |
273 | (target: $target:expr, $name:expr, $($field:tt)*) => { |
274 | $crate::span!( |
275 | target: $target, |
276 | $crate::Level::DEBUG, |
277 | $name, |
278 | $($field)* |
279 | ) |
280 | }; |
281 | (target: $target:expr, $name:expr) => { |
282 | $crate::debug_span!(target: $target, $name,) |
283 | }; |
284 | ($name:expr, $($field:tt)*) => { |
285 | $crate::span!( |
286 | target: module_path!(), |
287 | $crate::Level::DEBUG, |
288 | $name, |
289 | $($field)* |
290 | ) |
291 | }; |
292 | ($name:expr) => {$crate::debug_span!($name,)}; |
293 | } |
294 | |
295 | /// Constructs a span at the info level. |
296 | /// |
297 | /// [Fields] and [attributes] are set using the same syntax as the [`span!`] |
298 | /// macro. |
299 | /// |
300 | /// See [the top-level documentation][lib] for details on the syntax accepted by |
301 | /// this macro. |
302 | /// |
303 | /// [lib]: crate#using-the-macros |
304 | /// [attributes]: crate#configuring-attributes |
305 | /// [Fields]: crate#recording-fields |
306 | /// [`span!`]: crate::span! |
307 | /// |
308 | /// # Examples |
309 | /// |
310 | /// ```rust |
311 | /// # use tracing::{span, info_span, Level}; |
312 | /// # fn main() { |
313 | /// info_span!("my_span" ); |
314 | /// // is equivalent to: |
315 | /// span!(Level::INFO, "my_span" ); |
316 | /// # } |
317 | /// ``` |
318 | /// |
319 | /// ```rust |
320 | /// # use tracing::info_span; |
321 | /// # fn main() { |
322 | /// let span = info_span!("my span" ); |
323 | /// span.in_scope(|| { |
324 | /// // do work inside the span... |
325 | /// }); |
326 | /// # } |
327 | /// ``` |
328 | #[macro_export ] |
329 | macro_rules! info_span { |
330 | (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { |
331 | $crate::span!( |
332 | target: $target, |
333 | parent: $parent, |
334 | $crate::Level::INFO, |
335 | $name, |
336 | $($field)* |
337 | ) |
338 | }; |
339 | (target: $target:expr, parent: $parent:expr, $name:expr) => { |
340 | $crate::info_span!(target: $target, parent: $parent, $name,) |
341 | }; |
342 | (parent: $parent:expr, $name:expr, $($field:tt)*) => { |
343 | $crate::span!( |
344 | target: module_path!(), |
345 | parent: $parent, |
346 | $crate::Level::INFO, |
347 | $name, |
348 | $($field)* |
349 | ) |
350 | }; |
351 | (parent: $parent:expr, $name:expr) => { |
352 | $crate::info_span!(parent: $parent, $name,) |
353 | }; |
354 | (target: $target:expr, $name:expr, $($field:tt)*) => { |
355 | $crate::span!( |
356 | target: $target, |
357 | $crate::Level::INFO, |
358 | $name, |
359 | $($field)* |
360 | ) |
361 | }; |
362 | (target: $target:expr, $name:expr) => { |
363 | $crate::info_span!(target: $target, $name,) |
364 | }; |
365 | ($name:expr, $($field:tt)*) => { |
366 | $crate::span!( |
367 | target: module_path!(), |
368 | $crate::Level::INFO, |
369 | $name, |
370 | $($field)* |
371 | ) |
372 | }; |
373 | ($name:expr) => {$crate::info_span!($name,)}; |
374 | } |
375 | |
376 | /// Constructs a span at the warn level. |
377 | /// |
378 | /// [Fields] and [attributes] are set using the same syntax as the [`span!`] |
379 | /// macro. |
380 | /// |
381 | /// See [the top-level documentation][lib] for details on the syntax accepted by |
382 | /// this macro. |
383 | /// |
384 | /// [lib]: crate#using-the-macros |
385 | /// [attributes]: crate#configuring-attributes |
386 | /// [Fields]: crate#recording-fields |
387 | /// [`span!`]: crate::span! |
388 | /// |
389 | /// # Examples |
390 | /// |
391 | /// ```rust |
392 | /// # use tracing::{warn_span, span, Level}; |
393 | /// # fn main() { |
394 | /// warn_span!("my_span" ); |
395 | /// // is equivalent to: |
396 | /// span!(Level::WARN, "my_span" ); |
397 | /// # } |
398 | /// ``` |
399 | /// |
400 | /// ```rust |
401 | /// use tracing::warn_span; |
402 | /// # fn main() { |
403 | /// let span = warn_span!("my span" ); |
404 | /// span.in_scope(|| { |
405 | /// // do work inside the span... |
406 | /// }); |
407 | /// # } |
408 | /// ``` |
409 | #[macro_export ] |
410 | macro_rules! warn_span { |
411 | (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { |
412 | $crate::span!( |
413 | target: $target, |
414 | parent: $parent, |
415 | $crate::Level::WARN, |
416 | $name, |
417 | $($field)* |
418 | ) |
419 | }; |
420 | (target: $target:expr, parent: $parent:expr, $name:expr) => { |
421 | $crate::warn_span!(target: $target, parent: $parent, $name,) |
422 | }; |
423 | (parent: $parent:expr, $name:expr, $($field:tt)*) => { |
424 | $crate::span!( |
425 | target: module_path!(), |
426 | parent: $parent, |
427 | $crate::Level::WARN, |
428 | $name, |
429 | $($field)* |
430 | ) |
431 | }; |
432 | (parent: $parent:expr, $name:expr) => { |
433 | $crate::warn_span!(parent: $parent, $name,) |
434 | }; |
435 | (target: $target:expr, $name:expr, $($field:tt)*) => { |
436 | $crate::span!( |
437 | target: $target, |
438 | $crate::Level::WARN, |
439 | $name, |
440 | $($field)* |
441 | ) |
442 | }; |
443 | (target: $target:expr, $name:expr) => { |
444 | $crate::warn_span!(target: $target, $name,) |
445 | }; |
446 | ($name:expr, $($field:tt)*) => { |
447 | $crate::span!( |
448 | target: module_path!(), |
449 | $crate::Level::WARN, |
450 | $name, |
451 | $($field)* |
452 | ) |
453 | }; |
454 | ($name:expr) => {$crate::warn_span!($name,)}; |
455 | } |
456 | /// Constructs a span at the error level. |
457 | /// |
458 | /// [Fields] and [attributes] are set using the same syntax as the [`span!`] |
459 | /// macro. |
460 | /// |
461 | /// See [the top-level documentation][lib] for details on the syntax accepted by |
462 | /// this macro. |
463 | /// |
464 | /// [lib]: crate#using-the-macros |
465 | /// [attributes]: crate#configuring-attributes |
466 | /// [Fields]: crate#recording-fields |
467 | /// [`span!`]: crate::span! |
468 | /// |
469 | /// # Examples |
470 | /// |
471 | /// ```rust |
472 | /// # use tracing::{span, error_span, Level}; |
473 | /// # fn main() { |
474 | /// error_span!("my_span" ); |
475 | /// // is equivalent to: |
476 | /// span!(Level::ERROR, "my_span" ); |
477 | /// # } |
478 | /// ``` |
479 | /// |
480 | /// ```rust |
481 | /// # use tracing::error_span; |
482 | /// # fn main() { |
483 | /// let span = error_span!("my span" ); |
484 | /// span.in_scope(|| { |
485 | /// // do work inside the span... |
486 | /// }); |
487 | /// # } |
488 | /// ``` |
489 | #[macro_export ] |
490 | macro_rules! error_span { |
491 | (target: $target:expr, parent: $parent:expr, $name:expr, $($field:tt)*) => { |
492 | $crate::span!( |
493 | target: $target, |
494 | parent: $parent, |
495 | $crate::Level::ERROR, |
496 | $name, |
497 | $($field)* |
498 | ) |
499 | }; |
500 | (target: $target:expr, parent: $parent:expr, $name:expr) => { |
501 | $crate::error_span!(target: $target, parent: $parent, $name,) |
502 | }; |
503 | (parent: $parent:expr, $name:expr, $($field:tt)*) => { |
504 | $crate::span!( |
505 | target: module_path!(), |
506 | parent: $parent, |
507 | $crate::Level::ERROR, |
508 | $name, |
509 | $($field)* |
510 | ) |
511 | }; |
512 | (parent: $parent:expr, $name:expr) => { |
513 | $crate::error_span!(parent: $parent, $name,) |
514 | }; |
515 | (target: $target:expr, $name:expr, $($field:tt)*) => { |
516 | $crate::span!( |
517 | target: $target, |
518 | $crate::Level::ERROR, |
519 | $name, |
520 | $($field)* |
521 | ) |
522 | }; |
523 | (target: $target:expr, $name:expr) => { |
524 | $crate::error_span!(target: $target, $name,) |
525 | }; |
526 | ($name:expr, $($field:tt)*) => { |
527 | $crate::span!( |
528 | target: module_path!(), |
529 | $crate::Level::ERROR, |
530 | $name, |
531 | $($field)* |
532 | ) |
533 | }; |
534 | ($name:expr) => {$crate::error_span!($name,)}; |
535 | } |
536 | |
537 | /// Constructs a new `Event`. |
538 | /// |
539 | /// The event macro is invoked with a `Level` and up to 32 key-value fields. |
540 | /// Optionally, a format string and arguments may follow the fields; this will |
541 | /// be used to construct an implicit field named "message". |
542 | /// |
543 | /// See [the top-level documentation][lib] for details on the syntax accepted by |
544 | /// this macro. |
545 | /// |
546 | /// [lib]: crate#using-the-macros |
547 | /// |
548 | /// # Examples |
549 | /// |
550 | /// ```rust |
551 | /// use tracing::{event, Level}; |
552 | /// |
553 | /// # fn main() { |
554 | /// let data = (42, "forty-two" ); |
555 | /// let private_data = "private" ; |
556 | /// let error = "a bad error" ; |
557 | /// |
558 | /// event!(Level::ERROR, %error, "Received error" ); |
559 | /// event!( |
560 | /// target: "app_events" , |
561 | /// Level::WARN, |
562 | /// private_data, |
563 | /// ?data, |
564 | /// "App warning: {}" , |
565 | /// error |
566 | /// ); |
567 | /// event!(name: "answer" , Level::INFO, the_answer = data.0); |
568 | /// event!(Level::INFO, the_answer = data.0); |
569 | /// # } |
570 | /// ``` |
571 | /// |
572 | // /// Note that *unlike `span!`*, `event!` requires a value for all fields. As |
573 | // /// events are recorded immediately when the macro is invoked, there is no |
574 | // /// opportunity for fields to be recorded later. A trailing comma on the final |
575 | // /// field is valid. |
576 | // /// |
577 | // /// For example, the following does not compile: |
578 | // /// ```rust,compile_fail |
579 | // /// # use tracing::{Level, event}; |
580 | // /// # fn main() { |
581 | // /// event!(Level::INFO, foo = 5, bad_field, bar = "hello") |
582 | // /// #} |
583 | // /// ``` |
584 | #[macro_export ] |
585 | macro_rules! event { |
586 | // Name / target / parent. |
587 | (name: $name:expr, target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({ |
588 | use $crate::__macro_support::Callsite as _; |
589 | static __CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! { |
590 | name: $name, |
591 | kind: $crate::metadata::Kind::EVENT, |
592 | target: $target, |
593 | level: $lvl, |
594 | fields: $($fields)* |
595 | }; |
596 | |
597 | let enabled = $crate::level_enabled!($lvl) && { |
598 | let interest = __CALLSITE.interest(); |
599 | !interest.is_never() && $crate::__macro_support::__is_enabled(__CALLSITE.metadata(), interest) |
600 | }; |
601 | if enabled { |
602 | (|value_set: $crate::field::ValueSet| { |
603 | $crate::__tracing_log!( |
604 | $lvl, |
605 | __CALLSITE, |
606 | &value_set |
607 | ); |
608 | let meta = __CALLSITE.metadata(); |
609 | // event with explicit parent |
610 | $crate::Event::child_of( |
611 | $parent, |
612 | meta, |
613 | &value_set |
614 | ); |
615 | })($crate::valueset!(__CALLSITE.metadata().fields(), $($fields)*)); |
616 | } else { |
617 | $crate::__tracing_log!( |
618 | $lvl, |
619 | __CALLSITE, |
620 | &$crate::valueset!(__CALLSITE.metadata().fields(), $($fields)*) |
621 | ); |
622 | } |
623 | }); |
624 | (name: $name:expr, target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( |
625 | $crate::event!( |
626 | name: $name, |
627 | target: $target, |
628 | parent: $parent, |
629 | $lvl, |
630 | { message = ::core::format_args!($($arg)+), $($fields)* } |
631 | ) |
632 | ); |
633 | (name: $name:expr, target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( |
634 | $crate::event!(name: $name, target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* }) |
635 | ); |
636 | (name: $name:expr, target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( |
637 | $crate::event!(name: $name, target: $target, parent: $parent, $lvl, { $($arg)+ }) |
638 | ); |
639 | |
640 | // Name / target. |
641 | (name: $name:expr, target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ |
642 | use $crate::__macro_support::Callsite as _; |
643 | static __CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! { |
644 | name: $name, |
645 | kind: $crate::metadata::Kind::EVENT, |
646 | target: $target, |
647 | level: $lvl, |
648 | fields: $($fields)* |
649 | }; |
650 | let enabled = $crate::level_enabled!($lvl) && { |
651 | let interest = __CALLSITE.interest(); |
652 | !interest.is_never() && $crate::__macro_support::__is_enabled(__CALLSITE.metadata(), interest) |
653 | }; |
654 | if enabled { |
655 | (|value_set: $crate::field::ValueSet| { |
656 | let meta = __CALLSITE.metadata(); |
657 | // event with contextual parent |
658 | $crate::Event::dispatch( |
659 | meta, |
660 | &value_set |
661 | ); |
662 | $crate::__tracing_log!( |
663 | $lvl, |
664 | __CALLSITE, |
665 | &value_set |
666 | ); |
667 | })($crate::valueset!(__CALLSITE.metadata().fields(), $($fields)*)); |
668 | } else { |
669 | $crate::__tracing_log!( |
670 | $lvl, |
671 | __CALLSITE, |
672 | &$crate::valueset!(__CALLSITE.metadata().fields(), $($fields)*) |
673 | ); |
674 | } |
675 | }); |
676 | (name: $name:expr, target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( |
677 | $crate::event!( |
678 | name: $name, |
679 | target: $target, |
680 | $lvl, |
681 | { message = ::core::format_args!($($arg)+), $($fields)* } |
682 | ) |
683 | ); |
684 | (name: $name:expr, target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( |
685 | $crate::event!(name: $name, target: $target, $lvl, { $($k).+ = $($fields)* }) |
686 | ); |
687 | (name: $name:expr, target: $target:expr, $lvl:expr, $($arg:tt)+) => ( |
688 | $crate::event!(name: $name, target: $target, $lvl, { $($arg)+ }) |
689 | ); |
690 | |
691 | // Target / parent. |
692 | (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({ |
693 | use $crate::__macro_support::Callsite as _; |
694 | static __CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite2! { |
695 | name: $crate::__macro_support::concat!( |
696 | "event " , |
697 | file!(), |
698 | ":" , |
699 | line!() |
700 | ), |
701 | kind: $crate::metadata::Kind::EVENT, |
702 | target: $target, |
703 | level: $lvl, |
704 | fields: $($fields)* |
705 | }; |
706 | |
707 | let enabled = $crate::level_enabled!($lvl) && { |
708 | let interest = __CALLSITE.interest(); |
709 | !interest.is_never() && $crate::__macro_support::__is_enabled(__CALLSITE.metadata(), interest) |
710 | }; |
711 | if enabled { |
712 | (|value_set: $crate::field::ValueSet| { |
713 | $crate::__tracing_log!( |
714 | $lvl, |
715 | __CALLSITE, |
716 | &value_set |
717 | ); |
718 | let meta = __CALLSITE.metadata(); |
719 | // event with explicit parent |
720 | $crate::Event::child_of( |
721 | $parent, |
722 | meta, |
723 | &value_set |
724 | ); |
725 | })($crate::valueset!(__CALLSITE.metadata().fields(), $($fields)*)); |
726 | } else { |
727 | $crate::__tracing_log!( |
728 | $lvl, |
729 | __CALLSITE, |
730 | &$crate::valueset!(__CALLSITE.metadata().fields(), $($fields)*) |
731 | ); |
732 | } |
733 | }); |
734 | (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( |
735 | $crate::event!( |
736 | target: $target, |
737 | parent: $parent, |
738 | $lvl, |
739 | { message = ::core::format_args!($($arg)+), $($fields)* } |
740 | ) |
741 | ); |
742 | (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( |
743 | $crate::event!(target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* }) |
744 | ); |
745 | (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( |
746 | $crate::event!(target: $target, parent: $parent, $lvl, { $($arg)+ }) |
747 | ); |
748 | |
749 | // Name / parent. |
750 | (name: $name:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({ |
751 | use $crate::__macro_support::Callsite as _; |
752 | static __CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! { |
753 | name: $name, |
754 | kind: $crate::metadata::Kind::EVENT, |
755 | target: module_path!(), |
756 | level: $lvl, |
757 | fields: $($fields)* |
758 | }; |
759 | |
760 | let enabled = $crate::level_enabled!($lvl) && { |
761 | let interest = __CALLSITE.interest(); |
762 | !interest.is_never() && __CALLSITE.is_enabled(interest) |
763 | }; |
764 | if enabled { |
765 | (|value_set: $crate::field::ValueSet| { |
766 | $crate::__tracing_log!( |
767 | $lvl, |
768 | __CALLSITE, |
769 | &value_set |
770 | ); |
771 | let meta = __CALLSITE.metadata(); |
772 | // event with explicit parent |
773 | $crate::Event::child_of( |
774 | $parent, |
775 | meta, |
776 | &value_set |
777 | ); |
778 | })($crate::valueset!(__CALLSITE.metadata().fields(), $($fields)*)); |
779 | } else { |
780 | $crate::__tracing_log!( |
781 | $lvl, |
782 | __CALLSITE, |
783 | &$crate::valueset!(__CALLSITE.metadata().fields(), $($fields)*) |
784 | ); |
785 | } |
786 | }); |
787 | (name: $name:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( |
788 | $crate::event!( |
789 | name: $name, |
790 | parent: $parent, |
791 | $lvl, |
792 | { message = ::core::format_args!($($arg)+), $($fields)* } |
793 | ) |
794 | ); |
795 | (name: $name:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( |
796 | $crate::event!(name: $name, parent: $parent, $lvl, { $($k).+ = $($fields)* }) |
797 | ); |
798 | (name: $name:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( |
799 | $crate::event!(name: $name, parent: $parent, $lvl, { $($arg)+ }) |
800 | ); |
801 | |
802 | // Name. |
803 | (name: $name:expr, $lvl:expr, { $($fields:tt)* } )=> ({ |
804 | use $crate::__macro_support::Callsite as _; |
805 | static __CALLSITE: $crate::__macro_support::MacroCallsite = $crate::callsite2! { |
806 | name: $name, |
807 | kind: $crate::metadata::Kind::EVENT, |
808 | target: module_path!(), |
809 | level: $lvl, |
810 | fields: $($fields)* |
811 | }; |
812 | let enabled = $crate::level_enabled!($lvl) && { |
813 | let interest = __CALLSITE.interest(); |
814 | !interest.is_never() && $crate::__macro_support::__is_enabled(__CALLSITE.metadata(), interest) |
815 | }; |
816 | if enabled { |
817 | (|value_set: $crate::field::ValueSet| { |
818 | let meta = __CALLSITE.metadata(); |
819 | // event with contextual parent |
820 | $crate::Event::dispatch( |
821 | meta, |
822 | &value_set |
823 | ); |
824 | $crate::__tracing_log!( |
825 | $lvl, |
826 | __CALLSITE, |
827 | &value_set |
828 | ); |
829 | })($crate::valueset!(__CALLSITE.metadata().fields(), $($fields)*)); |
830 | } else { |
831 | $crate::__tracing_log!( |
832 | $lvl, |
833 | __CALLSITE, |
834 | &$crate::valueset!(__CALLSITE.metadata().fields(), $($fields)*) |
835 | ); |
836 | } |
837 | }); |
838 | (name: $name:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( |
839 | $crate::event!( |
840 | name: $name, |
841 | $lvl, |
842 | { message = ::core::format_args!($($arg)+), $($fields)* } |
843 | ) |
844 | ); |
845 | (name: $name:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( |
846 | $crate::event!(name: $name, $lvl, { $($k).+ = $($fields)* }) |
847 | ); |
848 | (name: $name:expr, $lvl:expr, $($arg:tt)+ ) => ( |
849 | $crate::event!(name: $name, $lvl, { $($arg)+ }) |
850 | ); |
851 | |
852 | // Target. |
853 | (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ |
854 | use $crate::__macro_support::Callsite as _; |
855 | static __CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite2! { |
856 | name: $crate::__macro_support::concat!( |
857 | "event " , |
858 | file!(), |
859 | ":" , |
860 | line!() |
861 | ), |
862 | kind: $crate::metadata::Kind::EVENT, |
863 | target: $target, |
864 | level: $lvl, |
865 | fields: $($fields)* |
866 | }; |
867 | let enabled = $crate::level_enabled!($lvl) && { |
868 | let interest = __CALLSITE.interest(); |
869 | !interest.is_never() && $crate::__macro_support::__is_enabled(__CALLSITE.metadata(), interest) |
870 | }; |
871 | if enabled { |
872 | (|value_set: $crate::field::ValueSet| { |
873 | let meta = __CALLSITE.metadata(); |
874 | // event with contextual parent |
875 | $crate::Event::dispatch( |
876 | meta, |
877 | &value_set |
878 | ); |
879 | $crate::__tracing_log!( |
880 | $lvl, |
881 | __CALLSITE, |
882 | &value_set |
883 | ); |
884 | })($crate::valueset!(__CALLSITE.metadata().fields(), $($fields)*)); |
885 | } else { |
886 | $crate::__tracing_log!( |
887 | $lvl, |
888 | __CALLSITE, |
889 | &$crate::valueset!(__CALLSITE.metadata().fields(), $($fields)*) |
890 | ); |
891 | } |
892 | }); |
893 | (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( |
894 | $crate::event!( |
895 | target: $target, |
896 | $lvl, |
897 | { message = ::core::format_args!($($arg)+), $($fields)* } |
898 | ) |
899 | ); |
900 | (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( |
901 | $crate::event!(target: $target, $lvl, { $($k).+ = $($fields)* }) |
902 | ); |
903 | (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => ( |
904 | $crate::event!(target: $target, $lvl, { $($arg)+ }) |
905 | ); |
906 | |
907 | // Parent. |
908 | (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( |
909 | $crate::event!( |
910 | target: module_path!(), |
911 | parent: $parent, |
912 | $lvl, |
913 | { message = ::core::format_args!($($arg)+), $($fields)* } |
914 | ) |
915 | ); |
916 | (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => ( |
917 | $crate::event!( |
918 | target: module_path!(), |
919 | parent: $parent, |
920 | $lvl, |
921 | { $($k).+ = $($field)*} |
922 | ) |
923 | ); |
924 | (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => ( |
925 | $crate::event!( |
926 | target: module_path!(), |
927 | parent: $parent, |
928 | $lvl, |
929 | { ?$($k).+ = $($field)*} |
930 | ) |
931 | ); |
932 | (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => ( |
933 | $crate::event!( |
934 | target: module_path!(), |
935 | parent: $parent, |
936 | $lvl, |
937 | { %$($k).+ = $($field)*} |
938 | ) |
939 | ); |
940 | (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => ( |
941 | $crate::event!( |
942 | target: module_path!(), |
943 | parent: $parent, |
944 | $lvl, |
945 | { $($k).+, $($field)*} |
946 | ) |
947 | ); |
948 | (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => ( |
949 | $crate::event!( |
950 | target: module_path!(), |
951 | parent: $parent, |
952 | $lvl, |
953 | { %$($k).+, $($field)*} |
954 | ) |
955 | ); |
956 | (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( |
957 | $crate::event!( |
958 | target: module_path!(), |
959 | parent: $parent, |
960 | $lvl, |
961 | { ?$($k).+, $($field)*} |
962 | ) |
963 | ); |
964 | (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => ( |
965 | $crate::event!(target: module_path!(), parent: $parent, $lvl, { $($arg)+ }) |
966 | ); |
967 | |
968 | // ... |
969 | ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( |
970 | $crate::event!( |
971 | target: module_path!(), |
972 | $lvl, |
973 | { message = ::core::format_args!($($arg)+), $($fields)* } |
974 | ) |
975 | ); |
976 | ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( |
977 | $crate::event!( |
978 | target: module_path!(), |
979 | $lvl, |
980 | { message = format_args!($($arg)+), $($fields)* } |
981 | ) |
982 | ); |
983 | ($lvl:expr, $($k:ident).+ = $($field:tt)*) => ( |
984 | $crate::event!( |
985 | target: module_path!(), |
986 | $lvl, |
987 | { $($k).+ = $($field)*} |
988 | ) |
989 | ); |
990 | ($lvl:expr, $($k:ident).+, $($field:tt)*) => ( |
991 | $crate::event!( |
992 | target: module_path!(), |
993 | $lvl, |
994 | { $($k).+, $($field)*} |
995 | ) |
996 | ); |
997 | ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( |
998 | $crate::event!( |
999 | target: module_path!(), |
1000 | $lvl, |
1001 | { ?$($k).+, $($field)*} |
1002 | ) |
1003 | ); |
1004 | ($lvl:expr, %$($k:ident).+, $($field:tt)*) => ( |
1005 | $crate::event!( |
1006 | target: module_path!(), |
1007 | $lvl, |
1008 | { %$($k).+, $($field)*} |
1009 | ) |
1010 | ); |
1011 | ($lvl:expr, ?$($k:ident).+) => ( |
1012 | $crate::event!($lvl, ?$($k).+,) |
1013 | ); |
1014 | ($lvl:expr, %$($k:ident).+) => ( |
1015 | $crate::event!($lvl, %$($k).+,) |
1016 | ); |
1017 | ($lvl:expr, $($k:ident).+) => ( |
1018 | $crate::event!($lvl, $($k).+,) |
1019 | ); |
1020 | ( $lvl:expr, $($arg:tt)+ ) => ( |
1021 | $crate::event!(target: module_path!(), $lvl, { $($arg)+ }) |
1022 | ); |
1023 | } |
1024 | |
1025 | /// Tests whether an event with the specified level and target would be enabled. |
1026 | /// |
1027 | /// This is similar to [`enabled!`], but queries the current subscriber specifically for |
1028 | /// an event, whereas [`enabled!`] queries for an event _or_ span. |
1029 | /// |
1030 | /// See the documentation for [`enabled!]` for more details on using this macro. |
1031 | /// See also [`span_enabled!`]. |
1032 | /// |
1033 | /// # Examples |
1034 | /// |
1035 | /// ```rust |
1036 | /// # use tracing::{event_enabled, Level}; |
1037 | /// if event_enabled!(target: "my_crate" , Level::DEBUG) { |
1038 | /// // some expensive work... |
1039 | /// } |
1040 | /// // simpler |
1041 | /// if event_enabled!(Level::DEBUG) { |
1042 | /// // some expensive work... |
1043 | /// } |
1044 | /// // with fields |
1045 | /// if event_enabled!(Level::DEBUG, foo_field) { |
1046 | /// // some expensive work... |
1047 | /// } |
1048 | /// ``` |
1049 | /// |
1050 | /// [`enabled!`]: crate::enabled |
1051 | /// [`span_enabled!`]: crate::span_enabled |
1052 | #[macro_export ] |
1053 | macro_rules! event_enabled { |
1054 | ($($rest:tt)*)=> ( |
1055 | $crate::enabled!(kind: $crate::metadata::Kind::EVENT, $($rest)*) |
1056 | ) |
1057 | } |
1058 | |
1059 | /// Tests whether a span with the specified level and target would be enabled. |
1060 | /// |
1061 | /// This is similar to [`enabled!`], but queries the current subscriber specifically for |
1062 | /// an event, whereas [`enabled!`] queries for an event _or_ span. |
1063 | /// |
1064 | /// See the documentation for [`enabled!]` for more details on using this macro. |
1065 | /// See also [`span_enabled!`]. |
1066 | /// |
1067 | /// # Examples |
1068 | /// |
1069 | /// ```rust |
1070 | /// # use tracing::{span_enabled, Level}; |
1071 | /// if span_enabled!(target: "my_crate" , Level::DEBUG) { |
1072 | /// // some expensive work... |
1073 | /// } |
1074 | /// // simpler |
1075 | /// if span_enabled!(Level::DEBUG) { |
1076 | /// // some expensive work... |
1077 | /// } |
1078 | /// // with fields |
1079 | /// if span_enabled!(Level::DEBUG, foo_field) { |
1080 | /// // some expensive work... |
1081 | /// } |
1082 | /// ``` |
1083 | /// |
1084 | /// [`enabled!`]: crate::enabled |
1085 | /// [`span_enabled!`]: crate::span_enabled |
1086 | #[macro_export ] |
1087 | macro_rules! span_enabled { |
1088 | ($($rest:tt)*)=> ( |
1089 | $crate::enabled!(kind: $crate::metadata::Kind::SPAN, $($rest)*) |
1090 | ) |
1091 | } |
1092 | |
1093 | /// Checks whether a span or event is [enabled] based on the provided [metadata]. |
1094 | /// |
1095 | /// [enabled]: crate::Subscriber::enabled |
1096 | /// [metadata]: crate::Metadata |
1097 | /// |
1098 | /// This macro is a specialized tool: it is intended to be used prior |
1099 | /// to an expensive computation required *just* for that event, but |
1100 | /// *cannot* be done as part of an argument to that event, such as |
1101 | /// when multiple events are emitted (e.g., iterating over a collection |
1102 | /// and emitting an event for each item). |
1103 | /// |
1104 | /// # Usage |
1105 | /// |
1106 | /// [Subscribers] can make filtering decisions based all the data included in a |
1107 | /// span or event's [`Metadata`]. This means that it is possible for `enabled!` |
1108 | /// to return a _false positive_ (indicating that something would be enabled |
1109 | /// when it actually would not be) or a _false negative_ (indicating that |
1110 | /// something would be disabled when it would actually be enabled). |
1111 | /// |
1112 | /// [Subscribers]: crate::subscriber::Subscriber |
1113 | /// [`Metadata`]: crate::metadata::Metadata |
1114 | /// |
1115 | /// This occurs when a subscriber is using a _more specific_ filter than the |
1116 | /// metadata provided to the `enabled!` macro. Some situations that can result |
1117 | /// in false positives or false negatives include: |
1118 | /// |
1119 | /// - If a subscriber is using a filter which may enable a span or event based |
1120 | /// on field names, but `enabled!` is invoked without listing field names, |
1121 | /// `enabled!` may return a false negative if a specific field name would |
1122 | /// cause the subscriber to enable something that would otherwise be disabled. |
1123 | /// - If a subscriber is using a filter which enables or disables specific events by |
1124 | /// file path and line number, a particular event may be enabled/disabled |
1125 | /// even if an `enabled!` invocation with the same level, target, and fields |
1126 | /// indicated otherwise. |
1127 | /// - The subscriber can choose to enable _only_ spans or _only_ events, which `enabled` |
1128 | /// will not reflect. |
1129 | /// |
1130 | /// `enabled!()` requires a [level](crate::Level) argument, an optional `target:` |
1131 | /// argument, and an optional set of field names. If the fields are not provided, |
1132 | /// they are considered to be unknown. `enabled!` attempts to match the |
1133 | /// syntax of `event!()` as closely as possible, which can be seen in the |
1134 | /// examples below. |
1135 | /// |
1136 | /// # Examples |
1137 | /// |
1138 | /// If the current subscriber is interested in recording `DEBUG`-level spans and |
1139 | /// events in the current file and module path, this will evaluate to true: |
1140 | /// ```rust |
1141 | /// use tracing::{enabled, Level}; |
1142 | /// |
1143 | /// if enabled!(Level::DEBUG) { |
1144 | /// // some expensive work... |
1145 | /// } |
1146 | /// ``` |
1147 | /// |
1148 | /// If the current subscriber is interested in recording spans and events |
1149 | /// in the current file and module path, with the target "my_crate", and at the |
1150 | /// level `DEBUG`, this will evaluate to true: |
1151 | /// ```rust |
1152 | /// # use tracing::{enabled, Level}; |
1153 | /// if enabled!(target: "my_crate" , Level::DEBUG) { |
1154 | /// // some expensive work... |
1155 | /// } |
1156 | /// ``` |
1157 | /// |
1158 | /// If the current subscriber is interested in recording spans and events |
1159 | /// in the current file and module path, with the target "my_crate", at |
1160 | /// the level `DEBUG`, and with a field named "hello", this will evaluate |
1161 | /// to true: |
1162 | /// |
1163 | /// ```rust |
1164 | /// # use tracing::{enabled, Level}; |
1165 | /// if enabled!(target: "my_crate" , Level::DEBUG, hello) { |
1166 | /// // some expensive work... |
1167 | /// } |
1168 | /// ``` |
1169 | /// |
1170 | /// # Alternatives |
1171 | /// |
1172 | /// `enabled!` queries subscribers with [`Metadata`] where |
1173 | /// [`is_event`] and [`is_span`] both return `false`. Alternatively, |
1174 | /// use [`event_enabled!`] or [`span_enabled!`] to ensure one of these |
1175 | /// returns true. |
1176 | /// |
1177 | /// |
1178 | /// [`Metadata`]: crate::Metadata |
1179 | /// [`is_event`]: crate::Metadata::is_event |
1180 | /// [`is_span`]: crate::Metadata::is_span |
1181 | /// [`enabled!`]: crate::enabled |
1182 | /// [`span_enabled!`]: crate::span_enabled |
1183 | #[macro_export ] |
1184 | macro_rules! enabled { |
1185 | (kind: $kind:expr, target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ |
1186 | if $crate::level_enabled!($lvl) { |
1187 | use $crate::__macro_support::Callsite as _; |
1188 | static __CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite2! { |
1189 | name: $crate::__macro_support::concat!( |
1190 | "enabled " , |
1191 | file!(), |
1192 | ":" , |
1193 | line!() |
1194 | ), |
1195 | kind: $kind.hint(), |
1196 | target: $target, |
1197 | level: $lvl, |
1198 | fields: $($fields)* |
1199 | }; |
1200 | let interest = __CALLSITE.interest(); |
1201 | if !interest.is_never() && $crate::__macro_support::__is_enabled(__CALLSITE.metadata(), interest) { |
1202 | let meta = __CALLSITE.metadata(); |
1203 | $crate::dispatcher::get_default(|current| current.enabled(meta)) |
1204 | } else { |
1205 | false |
1206 | } |
1207 | } else { |
1208 | false |
1209 | } |
1210 | }); |
1211 | // Just target and level |
1212 | (kind: $kind:expr, target: $target:expr, $lvl:expr ) => ( |
1213 | $crate::enabled!(kind: $kind, target: $target, $lvl, { }) |
1214 | ); |
1215 | (target: $target:expr, $lvl:expr ) => ( |
1216 | $crate::enabled!(kind: $crate::metadata::Kind::HINT, target: $target, $lvl, { }) |
1217 | ); |
1218 | |
1219 | // These four cases handle fields with no values |
1220 | (kind: $kind:expr, target: $target:expr, $lvl:expr, $($field:tt)*) => ( |
1221 | $crate::enabled!( |
1222 | kind: $kind, |
1223 | target: $target, |
1224 | $lvl, |
1225 | { $($field)*} |
1226 | ) |
1227 | ); |
1228 | (target: $target:expr, $lvl:expr, $($field:tt)*) => ( |
1229 | $crate::enabled!( |
1230 | kind: $crate::metadata::Kind::HINT, |
1231 | target: $target, |
1232 | $lvl, |
1233 | { $($field)*} |
1234 | ) |
1235 | ); |
1236 | |
1237 | // Level and field case |
1238 | (kind: $kind:expr, $lvl:expr, $($field:tt)*) => ( |
1239 | $crate::enabled!( |
1240 | kind: $kind, |
1241 | target: module_path!(), |
1242 | $lvl, |
1243 | { $($field)*} |
1244 | ) |
1245 | ); |
1246 | |
1247 | // Simplest `enabled!` case |
1248 | (kind: $kind:expr, $lvl:expr) => ( |
1249 | $crate::enabled!(kind: $kind, target: module_path!(), $lvl, { }) |
1250 | ); |
1251 | ($lvl:expr) => ( |
1252 | $crate::enabled!(kind: $crate::metadata::Kind::HINT, target: module_path!(), $lvl, { }) |
1253 | ); |
1254 | |
1255 | // Fallthrough from above |
1256 | ($lvl:expr, $($field:tt)*) => ( |
1257 | $crate::enabled!( |
1258 | kind: $crate::metadata::Kind::HINT, |
1259 | target: module_path!(), |
1260 | $lvl, |
1261 | { $($field)*} |
1262 | ) |
1263 | ); |
1264 | } |
1265 | |
1266 | /// Constructs an event at the trace level. |
1267 | /// |
1268 | /// This functions similarly to the [`event!`] macro. See [the top-level |
1269 | /// documentation][lib] for details on the syntax accepted by |
1270 | /// this macro. |
1271 | /// |
1272 | /// [`event!`]: crate::event! |
1273 | /// [lib]: crate#using-the-macros |
1274 | /// |
1275 | /// # Examples |
1276 | /// |
1277 | /// ```rust |
1278 | /// use tracing::trace; |
1279 | /// # #[derive(Debug, Copy, Clone)] struct Position { x: f32, y: f32 } |
1280 | /// # impl Position { |
1281 | /// # const ORIGIN: Self = Self { x: 0.0, y: 0.0 }; |
1282 | /// # fn dist(&self, other: Position) -> f32 { |
1283 | /// # let x = (other.x - self.x).exp2(); let y = (self.y - other.y).exp2(); |
1284 | /// # (x + y).sqrt() |
1285 | /// # } |
1286 | /// # } |
1287 | /// # fn main() { |
1288 | /// let pos = Position { x: 3.234, y: -1.223 }; |
1289 | /// let origin_dist = pos.dist(Position::ORIGIN); |
1290 | /// |
1291 | /// trace!(position = ?pos, ?origin_dist); |
1292 | /// trace!( |
1293 | /// target: "app_events" , |
1294 | /// position = ?pos, |
1295 | /// "x is {} and y is {}" , |
1296 | /// if pos.x >= 0.0 { "positive" } else { "negative" }, |
1297 | /// if pos.y >= 0.0 { "positive" } else { "negative" } |
1298 | /// ); |
1299 | /// trace!(name: "completed" , position = ?pos); |
1300 | /// # } |
1301 | /// ``` |
1302 | #[macro_export ] |
1303 | macro_rules! trace { |
1304 | // Name / target / parent. |
1305 | (name: $name:expr, target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1306 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::TRACE, { $($field)* }, $($arg)*) |
1307 | ); |
1308 | (name: $name:expr, target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1309 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) |
1310 | ); |
1311 | (name: $name:expr, target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1312 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) |
1313 | ); |
1314 | (name: $name:expr, target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1315 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) |
1316 | ); |
1317 | (name: $name:expr, target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
1318 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::TRACE, {}, $($arg)+) |
1319 | ); |
1320 | |
1321 | // Name / target. |
1322 | (name: $name:expr, target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1323 | $crate::event!(name: $name, target: $target, $crate::Level::TRACE, { $($field)* }, $($arg)*) |
1324 | ); |
1325 | (name: $name:expr, target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1326 | $crate::event!(name: $name, target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) |
1327 | ); |
1328 | (name: $name:expr, target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1329 | $crate::event!(name: $name, target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) |
1330 | ); |
1331 | (name: $name:expr, target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1332 | $crate::event!(name: $name, target: $target, $crate::Level::TRACE, { $($k).+ $($field)+ }) |
1333 | ); |
1334 | (name: $name:expr, target: $target:expr, $($arg:tt)+ ) => ( |
1335 | $crate::event!(name: $name, target: $target, $crate::Level::TRACE, {}, $($arg)+) |
1336 | ); |
1337 | |
1338 | // Target / parent. |
1339 | (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1340 | $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($field)* }, $($arg)*) |
1341 | ); |
1342 | (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1343 | $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) |
1344 | ); |
1345 | (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1346 | $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) |
1347 | ); |
1348 | (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1349 | $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) |
1350 | ); |
1351 | (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
1352 | $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, {}, $($arg)+) |
1353 | ); |
1354 | |
1355 | // Name / parent. |
1356 | (name: $name:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1357 | $crate::event!(name: $name, parent: $parent, $crate::Level::TRACE, { $($field)* }, $($arg)*) |
1358 | ); |
1359 | (name: $name:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1360 | $crate::event!(name: $name, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) |
1361 | ); |
1362 | (name: $name:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1363 | $crate::event!(name: $name, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) |
1364 | ); |
1365 | (name: $name:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1366 | $crate::event!(name: $name, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) |
1367 | ); |
1368 | (name: $name:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
1369 | $crate::event!(name: $name, parent: $parent, $crate::Level::TRACE, {}, $($arg)+) |
1370 | ); |
1371 | |
1372 | // Name. |
1373 | (name: $name:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1374 | $crate::event!(name: $name, $crate::Level::TRACE, { $($field)* }, $($arg)*) |
1375 | ); |
1376 | (name: $name:expr, $($k:ident).+ $($field:tt)* ) => ( |
1377 | $crate::event!(name: $name, $crate::Level::TRACE, { $($k).+ $($field)* }) |
1378 | ); |
1379 | (name: $name:expr, ?$($k:ident).+ $($field:tt)* ) => ( |
1380 | $crate::event!(name: $name, $crate::Level::TRACE, { ?$($k).+ $($field)* }) |
1381 | ); |
1382 | (name: $name:expr, %$($k:ident).+ $($field:tt)* ) => ( |
1383 | $crate::event!(name: $name, $crate::Level::TRACE, { %$($k).+ $($field)* }) |
1384 | ); |
1385 | (name: $name:expr, $($arg:tt)+ ) => ( |
1386 | $crate::event!(name: $name, $crate::Level::TRACE, {}, $($arg)+) |
1387 | ); |
1388 | |
1389 | // Target. |
1390 | (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1391 | $crate::event!(target: $target, $crate::Level::TRACE, { $($field)* }, $($arg)*) |
1392 | ); |
1393 | (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( |
1394 | $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)* }) |
1395 | ); |
1396 | (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( |
1397 | $crate::event!(target: $target, $crate::Level::TRACE, { ?$($k).+ $($field)* }) |
1398 | ); |
1399 | (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( |
1400 | $crate::event!(target: $target, $crate::Level::TRACE, { %$($k).+ $($field)* }) |
1401 | ); |
1402 | (target: $target:expr, $($arg:tt)+ ) => ( |
1403 | $crate::event!(target: $target, $crate::Level::TRACE, {}, $($arg)+) |
1404 | ); |
1405 | |
1406 | // Parent. |
1407 | (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( |
1408 | $crate::event!( |
1409 | target: module_path!(), |
1410 | parent: $parent, |
1411 | $crate::Level::TRACE, |
1412 | { $($field)+ }, |
1413 | $($arg)+ |
1414 | ) |
1415 | ); |
1416 | (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( |
1417 | $crate::event!( |
1418 | target: module_path!(), |
1419 | parent: $parent, |
1420 | $crate::Level::TRACE, |
1421 | { $($k).+ = $($field)*} |
1422 | ) |
1423 | ); |
1424 | (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( |
1425 | $crate::event!( |
1426 | target: module_path!(), |
1427 | parent: $parent, |
1428 | $crate::Level::TRACE, |
1429 | { ?$($k).+ = $($field)*} |
1430 | ) |
1431 | ); |
1432 | (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( |
1433 | $crate::event!( |
1434 | target: module_path!(), |
1435 | parent: $parent, |
1436 | $crate::Level::TRACE, |
1437 | { %$($k).+ = $($field)*} |
1438 | ) |
1439 | ); |
1440 | (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( |
1441 | $crate::event!( |
1442 | target: module_path!(), |
1443 | parent: $parent, |
1444 | $crate::Level::TRACE, |
1445 | { $($k).+, $($field)*} |
1446 | ) |
1447 | ); |
1448 | (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( |
1449 | $crate::event!( |
1450 | target: module_path!(), |
1451 | parent: $parent, |
1452 | $crate::Level::TRACE, |
1453 | { ?$($k).+, $($field)*} |
1454 | ) |
1455 | ); |
1456 | (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( |
1457 | $crate::event!( |
1458 | target: module_path!(), |
1459 | parent: $parent, |
1460 | $crate::Level::TRACE, |
1461 | { %$($k).+, $($field)*} |
1462 | ) |
1463 | ); |
1464 | (parent: $parent:expr, $($arg:tt)+) => ( |
1465 | $crate::event!( |
1466 | target: module_path!(), |
1467 | parent: $parent, |
1468 | $crate::Level::TRACE, |
1469 | {}, |
1470 | $($arg)+ |
1471 | ) |
1472 | ); |
1473 | |
1474 | // ... |
1475 | ({ $($field:tt)+ }, $($arg:tt)+ ) => ( |
1476 | $crate::event!( |
1477 | target: module_path!(), |
1478 | $crate::Level::TRACE, |
1479 | { $($field)+ }, |
1480 | $($arg)+ |
1481 | ) |
1482 | ); |
1483 | ($($k:ident).+ = $($field:tt)*) => ( |
1484 | $crate::event!( |
1485 | target: module_path!(), |
1486 | $crate::Level::TRACE, |
1487 | { $($k).+ = $($field)*} |
1488 | ) |
1489 | ); |
1490 | (?$($k:ident).+ = $($field:tt)*) => ( |
1491 | $crate::event!( |
1492 | target: module_path!(), |
1493 | $crate::Level::TRACE, |
1494 | { ?$($k).+ = $($field)*} |
1495 | ) |
1496 | ); |
1497 | (%$($k:ident).+ = $($field:tt)*) => ( |
1498 | $crate::event!( |
1499 | target: module_path!(), |
1500 | $crate::Level::TRACE, |
1501 | { %$($k).+ = $($field)*} |
1502 | ) |
1503 | ); |
1504 | ($($k:ident).+, $($field:tt)*) => ( |
1505 | $crate::event!( |
1506 | target: module_path!(), |
1507 | $crate::Level::TRACE, |
1508 | { $($k).+, $($field)*} |
1509 | ) |
1510 | ); |
1511 | (?$($k:ident).+, $($field:tt)*) => ( |
1512 | $crate::event!( |
1513 | target: module_path!(), |
1514 | $crate::Level::TRACE, |
1515 | { ?$($k).+, $($field)*} |
1516 | ) |
1517 | ); |
1518 | (%$($k:ident).+, $($field:tt)*) => ( |
1519 | $crate::event!( |
1520 | target: module_path!(), |
1521 | $crate::Level::TRACE, |
1522 | { %$($k).+, $($field)*} |
1523 | ) |
1524 | ); |
1525 | (?$($k:ident).+) => ( |
1526 | $crate::event!( |
1527 | target: module_path!(), |
1528 | $crate::Level::TRACE, |
1529 | { ?$($k).+ } |
1530 | ) |
1531 | ); |
1532 | (%$($k:ident).+) => ( |
1533 | $crate::event!( |
1534 | target: module_path!(), |
1535 | $crate::Level::TRACE, |
1536 | { %$($k).+ } |
1537 | ) |
1538 | ); |
1539 | ($($k:ident).+) => ( |
1540 | $crate::event!( |
1541 | target: module_path!(), |
1542 | $crate::Level::TRACE, |
1543 | { $($k).+ } |
1544 | ) |
1545 | ); |
1546 | ($($arg:tt)+) => ( |
1547 | $crate::event!( |
1548 | target: module_path!(), |
1549 | $crate::Level::TRACE, |
1550 | {}, |
1551 | $($arg)+ |
1552 | ) |
1553 | ); |
1554 | } |
1555 | |
1556 | /// Constructs an event at the debug level. |
1557 | /// |
1558 | /// This functions similarly to the [`event!`] macro. See [the top-level |
1559 | /// documentation][lib] for details on the syntax accepted by |
1560 | /// this macro. |
1561 | /// |
1562 | /// [`event!`]: crate::event! |
1563 | /// [lib]: crate#using-the-macros |
1564 | /// |
1565 | /// # Examples |
1566 | /// |
1567 | /// ```rust |
1568 | /// use tracing::debug; |
1569 | /// # fn main() { |
1570 | /// # #[derive(Debug)] struct Position { x: f32, y: f32 } |
1571 | /// |
1572 | /// let pos = Position { x: 3.234, y: -1.223 }; |
1573 | /// |
1574 | /// debug!(?pos.x, ?pos.y); |
1575 | /// debug!(target: "app_events" , position = ?pos, "New position" ); |
1576 | /// debug!(name: "completed" , position = ?pos); |
1577 | /// # } |
1578 | /// ``` |
1579 | #[macro_export ] |
1580 | macro_rules! debug { |
1581 | // Name / target / parent. |
1582 | (name: $name:expr, target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1583 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::DEBUG, { $($field)* }, $($arg)*) |
1584 | ); |
1585 | (name: $name:expr, target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1586 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) |
1587 | ); |
1588 | (name: $name:expr, target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1589 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) |
1590 | ); |
1591 | (name: $name:expr, target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1592 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) |
1593 | ); |
1594 | (name: $name:expr, target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
1595 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::DEBUG, {}, $($arg)+) |
1596 | ); |
1597 | |
1598 | // Name / target. |
1599 | (name: $name:expr, target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1600 | $crate::event!(name: $name, target: $target, $crate::Level::DEBUG, { $($field)* }, $($arg)*) |
1601 | ); |
1602 | (name: $name:expr, target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1603 | $crate::event!(name: $name, target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) |
1604 | ); |
1605 | (name: $name:expr, target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1606 | $crate::event!(name: $name, target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) |
1607 | ); |
1608 | (name: $name:expr, target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1609 | $crate::event!(name: $name, target: $target, $crate::Level::DEBUG, { $($k).+ $($field)+ }) |
1610 | ); |
1611 | (name: $name:expr, target: $target:expr, $($arg:tt)+ ) => ( |
1612 | $crate::event!(name: $name, target: $target, $crate::Level::DEBUG, {}, $($arg)+) |
1613 | ); |
1614 | |
1615 | // Target / parent. |
1616 | (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1617 | $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($field)* }, $($arg)*) |
1618 | ); |
1619 | (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1620 | $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) |
1621 | ); |
1622 | (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1623 | $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) |
1624 | ); |
1625 | (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1626 | $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) |
1627 | ); |
1628 | (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
1629 | $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, {}, $($arg)+) |
1630 | ); |
1631 | |
1632 | // Name / parent. |
1633 | (name: $name:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1634 | $crate::event!(name: $name, parent: $parent, $crate::Level::DEBUG, { $($field)* }, $($arg)*) |
1635 | ); |
1636 | (name: $name:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1637 | $crate::event!(name: $name, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) |
1638 | ); |
1639 | (name: $name:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1640 | $crate::event!(name: $name, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) |
1641 | ); |
1642 | (name: $name:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1643 | $crate::event!(name: $name, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) |
1644 | ); |
1645 | (name: $name:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
1646 | $crate::event!(name: $name, parent: $parent, $crate::Level::DEBUG, {}, $($arg)+) |
1647 | ); |
1648 | |
1649 | // Name. |
1650 | (name: $name:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1651 | $crate::event!(name: $name, $crate::Level::DEBUG, { $($field)* }, $($arg)*) |
1652 | ); |
1653 | (name: $name:expr, $($k:ident).+ $($field:tt)* ) => ( |
1654 | $crate::event!(name: $name, $crate::Level::DEBUG, { $($k).+ $($field)* }) |
1655 | ); |
1656 | (name: $name:expr, ?$($k:ident).+ $($field:tt)* ) => ( |
1657 | $crate::event!(name: $name, $crate::Level::DEBUG, { ?$($k).+ $($field)* }) |
1658 | ); |
1659 | (name: $name:expr, %$($k:ident).+ $($field:tt)* ) => ( |
1660 | $crate::event!(name: $name, $crate::Level::DEBUG, { %$($k).+ $($field)* }) |
1661 | ); |
1662 | (name: $name:expr, $($arg:tt)+ ) => ( |
1663 | $crate::event!(name: $name, $crate::Level::DEBUG, {}, $($arg)+) |
1664 | ); |
1665 | |
1666 | // Target. |
1667 | (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1668 | $crate::event!(target: $target, $crate::Level::DEBUG, { $($field)* }, $($arg)*) |
1669 | ); |
1670 | (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( |
1671 | $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)* }) |
1672 | ); |
1673 | (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( |
1674 | $crate::event!(target: $target, $crate::Level::DEBUG, { ?$($k).+ $($field)* }) |
1675 | ); |
1676 | (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( |
1677 | $crate::event!(target: $target, $crate::Level::DEBUG, { %$($k).+ $($field)* }) |
1678 | ); |
1679 | (target: $target:expr, $($arg:tt)+ ) => ( |
1680 | $crate::event!(target: $target, $crate::Level::DEBUG, {}, $($arg)+) |
1681 | ); |
1682 | |
1683 | // Parent. |
1684 | (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( |
1685 | $crate::event!( |
1686 | target: module_path!(), |
1687 | parent: $parent, |
1688 | $crate::Level::DEBUG, |
1689 | { $($field)+ }, |
1690 | $($arg)+ |
1691 | ) |
1692 | ); |
1693 | (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( |
1694 | $crate::event!( |
1695 | target: module_path!(), |
1696 | parent: $parent, |
1697 | $crate::Level::DEBUG, |
1698 | { $($k).+ = $($field)*} |
1699 | ) |
1700 | ); |
1701 | (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( |
1702 | $crate::event!( |
1703 | target: module_path!(), |
1704 | parent: $parent, |
1705 | $crate::Level::DEBUG, |
1706 | { ?$($k).+ = $($field)*} |
1707 | ) |
1708 | ); |
1709 | (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( |
1710 | $crate::event!( |
1711 | target: module_path!(), |
1712 | parent: $parent, |
1713 | $crate::Level::DEBUG, |
1714 | { %$($k).+ = $($field)*} |
1715 | ) |
1716 | ); |
1717 | (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( |
1718 | $crate::event!( |
1719 | target: module_path!(), |
1720 | parent: $parent, |
1721 | $crate::Level::DEBUG, |
1722 | { $($k).+, $($field)*} |
1723 | ) |
1724 | ); |
1725 | (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( |
1726 | $crate::event!( |
1727 | target: module_path!(), |
1728 | parent: $parent, |
1729 | $crate::Level::DEBUG, |
1730 | { ?$($k).+, $($field)*} |
1731 | ) |
1732 | ); |
1733 | (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( |
1734 | $crate::event!( |
1735 | target: module_path!(), |
1736 | parent: $parent, |
1737 | $crate::Level::DEBUG, |
1738 | { %$($k).+, $($field)*} |
1739 | ) |
1740 | ); |
1741 | (parent: $parent:expr, $($arg:tt)+) => ( |
1742 | $crate::event!( |
1743 | target: module_path!(), |
1744 | parent: $parent, |
1745 | $crate::Level::DEBUG, |
1746 | {}, |
1747 | $($arg)+ |
1748 | ) |
1749 | ); |
1750 | |
1751 | // ... |
1752 | ({ $($field:tt)+ }, $($arg:tt)+ ) => ( |
1753 | $crate::event!( |
1754 | target: module_path!(), |
1755 | $crate::Level::DEBUG, |
1756 | { $($field)+ }, |
1757 | $($arg)+ |
1758 | ) |
1759 | ); |
1760 | ($($k:ident).+ = $($field:tt)*) => ( |
1761 | $crate::event!( |
1762 | target: module_path!(), |
1763 | $crate::Level::DEBUG, |
1764 | { $($k).+ = $($field)*} |
1765 | ) |
1766 | ); |
1767 | (?$($k:ident).+ = $($field:tt)*) => ( |
1768 | $crate::event!( |
1769 | target: module_path!(), |
1770 | $crate::Level::DEBUG, |
1771 | { ?$($k).+ = $($field)*} |
1772 | ) |
1773 | ); |
1774 | (%$($k:ident).+ = $($field:tt)*) => ( |
1775 | $crate::event!( |
1776 | target: module_path!(), |
1777 | $crate::Level::DEBUG, |
1778 | { %$($k).+ = $($field)*} |
1779 | ) |
1780 | ); |
1781 | ($($k:ident).+, $($field:tt)*) => ( |
1782 | $crate::event!( |
1783 | target: module_path!(), |
1784 | $crate::Level::DEBUG, |
1785 | { $($k).+, $($field)*} |
1786 | ) |
1787 | ); |
1788 | (?$($k:ident).+, $($field:tt)*) => ( |
1789 | $crate::event!( |
1790 | target: module_path!(), |
1791 | $crate::Level::DEBUG, |
1792 | { ?$($k).+, $($field)*} |
1793 | ) |
1794 | ); |
1795 | (%$($k:ident).+, $($field:tt)*) => ( |
1796 | $crate::event!( |
1797 | target: module_path!(), |
1798 | $crate::Level::DEBUG, |
1799 | { %$($k).+, $($field)*} |
1800 | ) |
1801 | ); |
1802 | (?$($k:ident).+) => ( |
1803 | $crate::event!( |
1804 | target: module_path!(), |
1805 | $crate::Level::DEBUG, |
1806 | { ?$($k).+ } |
1807 | ) |
1808 | ); |
1809 | (%$($k:ident).+) => ( |
1810 | $crate::event!( |
1811 | target: module_path!(), |
1812 | $crate::Level::DEBUG, |
1813 | { %$($k).+ } |
1814 | ) |
1815 | ); |
1816 | ($($k:ident).+) => ( |
1817 | $crate::event!( |
1818 | target: module_path!(), |
1819 | $crate::Level::DEBUG, |
1820 | { $($k).+ } |
1821 | ) |
1822 | ); |
1823 | ($($arg:tt)+) => ( |
1824 | $crate::event!( |
1825 | target: module_path!(), |
1826 | $crate::Level::DEBUG, |
1827 | {}, |
1828 | $($arg)+ |
1829 | ) |
1830 | ); |
1831 | } |
1832 | |
1833 | /// Constructs an event at the info level. |
1834 | /// |
1835 | /// This functions similarly to the [`event!`] macro. See [the top-level |
1836 | /// documentation][lib] for details on the syntax accepted by |
1837 | /// this macro. |
1838 | /// |
1839 | /// [`event!`]: crate::event! |
1840 | /// [lib]: crate#using-the-macros |
1841 | /// |
1842 | /// # Examples |
1843 | /// |
1844 | /// ```rust |
1845 | /// use tracing::info; |
1846 | /// # // this is so the test will still work in no-std mode |
1847 | /// # #[derive(Debug)] |
1848 | /// # pub struct Ipv4Addr; |
1849 | /// # impl Ipv4Addr { fn new(o1: u8, o2: u8, o3: u8, o4: u8) -> Self { Self } } |
1850 | /// # fn main() { |
1851 | /// # struct Connection { port: u32, speed: f32 } |
1852 | /// use tracing::field; |
1853 | /// |
1854 | /// let addr = Ipv4Addr::new(127, 0, 0, 1); |
1855 | /// let conn = Connection { port: 40, speed: 3.20 }; |
1856 | /// |
1857 | /// info!(conn.port, "connected to {:?}" , addr); |
1858 | /// info!( |
1859 | /// target: "connection_events" , |
1860 | /// ip = ?addr, |
1861 | /// conn.port, |
1862 | /// ?conn.speed, |
1863 | /// ); |
1864 | /// info!(name: "completed" , "completed connection to {:?}" , addr); |
1865 | /// # } |
1866 | /// ``` |
1867 | #[macro_export ] |
1868 | macro_rules! info { |
1869 | // Name / target / parent. |
1870 | (name: $name:expr, target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1871 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*) |
1872 | ); |
1873 | (name: $name:expr, target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1874 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) |
1875 | ); |
1876 | (name: $name:expr, target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1877 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) |
1878 | ); |
1879 | (name: $name:expr, target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1880 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) |
1881 | ); |
1882 | (name: $name:expr, target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
1883 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::INFO, {}, $($arg)+) |
1884 | ); |
1885 | |
1886 | // Name / target. |
1887 | (name: $name:expr, target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1888 | $crate::event!(name: $name, target: $target, $crate::Level::INFO, { $($field)* }, $($arg)*) |
1889 | ); |
1890 | (name: $name:expr, target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1891 | $crate::event!(name: $name, target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) |
1892 | ); |
1893 | (name: $name:expr, target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1894 | $crate::event!(name: $name, target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) |
1895 | ); |
1896 | (name: $name:expr, target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1897 | $crate::event!(name: $name, target: $target, $crate::Level::INFO, { $($k).+ $($field)+ }) |
1898 | ); |
1899 | (name: $name:expr, target: $target:expr, $($arg:tt)+ ) => ( |
1900 | $crate::event!(name: $name, target: $target, $crate::Level::INFO, {}, $($arg)+) |
1901 | ); |
1902 | |
1903 | // Target / parent. |
1904 | (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1905 | $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*) |
1906 | ); |
1907 | (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1908 | $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) |
1909 | ); |
1910 | (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1911 | $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) |
1912 | ); |
1913 | (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1914 | $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) |
1915 | ); |
1916 | (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
1917 | $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, {}, $($arg)+) |
1918 | ); |
1919 | |
1920 | // Name / parent. |
1921 | (name: $name:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1922 | $crate::event!(name: $name, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*) |
1923 | ); |
1924 | (name: $name:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1925 | $crate::event!(name: $name, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) |
1926 | ); |
1927 | (name: $name:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1928 | $crate::event!(name: $name, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) |
1929 | ); |
1930 | (name: $name:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1931 | $crate::event!(name: $name, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) |
1932 | ); |
1933 | (name: $name:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
1934 | $crate::event!(name: $name, parent: $parent, $crate::Level::INFO, {}, $($arg)+) |
1935 | ); |
1936 | |
1937 | // Name. |
1938 | (name: $name:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1939 | $crate::event!(name: $name, $crate::Level::INFO, { $($field)* }, $($arg)*) |
1940 | ); |
1941 | (name: $name:expr, $($k:ident).+ $($field:tt)* ) => ( |
1942 | $crate::event!(name: $name, $crate::Level::INFO, { $($k).+ $($field)* }) |
1943 | ); |
1944 | (name: $name:expr, ?$($k:ident).+ $($field:tt)* ) => ( |
1945 | $crate::event!(name: $name, $crate::Level::INFO, { ?$($k).+ $($field)* }) |
1946 | ); |
1947 | (name: $name:expr, %$($k:ident).+ $($field:tt)* ) => ( |
1948 | $crate::event!(name: $name, $crate::Level::INFO, { %$($k).+ $($field)* }) |
1949 | ); |
1950 | (name: $name:expr, $($arg:tt)+ ) => ( |
1951 | $crate::event!(name: $name, $crate::Level::INFO, {}, $($arg)+) |
1952 | ); |
1953 | |
1954 | // Target. |
1955 | (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1956 | $crate::event!(target: $target, $crate::Level::INFO, { $($field)* }, $($arg)*) |
1957 | ); |
1958 | (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( |
1959 | $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)* }) |
1960 | ); |
1961 | (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( |
1962 | $crate::event!(target: $target, $crate::Level::INFO, { ?$($k).+ $($field)* }) |
1963 | ); |
1964 | (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( |
1965 | $crate::event!(target: $target, $crate::Level::INFO, { %$($k).+ $($field)* }) |
1966 | ); |
1967 | (target: $target:expr, $($arg:tt)+ ) => ( |
1968 | $crate::event!(target: $target, $crate::Level::INFO, {}, $($arg)+) |
1969 | ); |
1970 | |
1971 | // Parent. |
1972 | (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( |
1973 | $crate::event!( |
1974 | target: module_path!(), |
1975 | parent: $parent, |
1976 | $crate::Level::INFO, |
1977 | { $($field)+ }, |
1978 | $($arg)+ |
1979 | ) |
1980 | ); |
1981 | (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( |
1982 | $crate::event!( |
1983 | target: module_path!(), |
1984 | parent: $parent, |
1985 | $crate::Level::INFO, |
1986 | { $($k).+ = $($field)*} |
1987 | ) |
1988 | ); |
1989 | (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( |
1990 | $crate::event!( |
1991 | target: module_path!(), |
1992 | parent: $parent, |
1993 | $crate::Level::INFO, |
1994 | { ?$($k).+ = $($field)*} |
1995 | ) |
1996 | ); |
1997 | (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( |
1998 | $crate::event!( |
1999 | target: module_path!(), |
2000 | parent: $parent, |
2001 | $crate::Level::INFO, |
2002 | { %$($k).+ = $($field)*} |
2003 | ) |
2004 | ); |
2005 | (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( |
2006 | $crate::event!( |
2007 | target: module_path!(), |
2008 | parent: $parent, |
2009 | $crate::Level::INFO, |
2010 | { $($k).+, $($field)*} |
2011 | ) |
2012 | ); |
2013 | (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( |
2014 | $crate::event!( |
2015 | target: module_path!(), |
2016 | parent: $parent, |
2017 | $crate::Level::INFO, |
2018 | { ?$($k).+, $($field)*} |
2019 | ) |
2020 | ); |
2021 | (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( |
2022 | $crate::event!( |
2023 | target: module_path!(), |
2024 | parent: $parent, |
2025 | $crate::Level::INFO, |
2026 | { %$($k).+, $($field)*} |
2027 | ) |
2028 | ); |
2029 | (parent: $parent:expr, $($arg:tt)+) => ( |
2030 | $crate::event!( |
2031 | target: module_path!(), |
2032 | parent: $parent, |
2033 | $crate::Level::INFO, |
2034 | {}, |
2035 | $($arg)+ |
2036 | ) |
2037 | ); |
2038 | |
2039 | // ... |
2040 | ({ $($field:tt)+ }, $($arg:tt)+ ) => ( |
2041 | $crate::event!( |
2042 | target: module_path!(), |
2043 | $crate::Level::INFO, |
2044 | { $($field)+ }, |
2045 | $($arg)+ |
2046 | ) |
2047 | ); |
2048 | ($($k:ident).+ = $($field:tt)*) => ( |
2049 | $crate::event!( |
2050 | target: module_path!(), |
2051 | $crate::Level::INFO, |
2052 | { $($k).+ = $($field)*} |
2053 | ) |
2054 | ); |
2055 | (?$($k:ident).+ = $($field:tt)*) => ( |
2056 | $crate::event!( |
2057 | target: module_path!(), |
2058 | $crate::Level::INFO, |
2059 | { ?$($k).+ = $($field)*} |
2060 | ) |
2061 | ); |
2062 | (%$($k:ident).+ = $($field:tt)*) => ( |
2063 | $crate::event!( |
2064 | target: module_path!(), |
2065 | $crate::Level::INFO, |
2066 | { %$($k).+ = $($field)*} |
2067 | ) |
2068 | ); |
2069 | ($($k:ident).+, $($field:tt)*) => ( |
2070 | $crate::event!( |
2071 | target: module_path!(), |
2072 | $crate::Level::INFO, |
2073 | { $($k).+, $($field)*} |
2074 | ) |
2075 | ); |
2076 | (?$($k:ident).+, $($field:tt)*) => ( |
2077 | $crate::event!( |
2078 | target: module_path!(), |
2079 | $crate::Level::INFO, |
2080 | { ?$($k).+, $($field)*} |
2081 | ) |
2082 | ); |
2083 | (%$($k:ident).+, $($field:tt)*) => ( |
2084 | $crate::event!( |
2085 | target: module_path!(), |
2086 | $crate::Level::INFO, |
2087 | { %$($k).+, $($field)*} |
2088 | ) |
2089 | ); |
2090 | (?$($k:ident).+) => ( |
2091 | $crate::event!( |
2092 | target: module_path!(), |
2093 | $crate::Level::INFO, |
2094 | { ?$($k).+ } |
2095 | ) |
2096 | ); |
2097 | (%$($k:ident).+) => ( |
2098 | $crate::event!( |
2099 | target: module_path!(), |
2100 | $crate::Level::INFO, |
2101 | { %$($k).+ } |
2102 | ) |
2103 | ); |
2104 | ($($k:ident).+) => ( |
2105 | $crate::event!( |
2106 | target: module_path!(), |
2107 | $crate::Level::INFO, |
2108 | { $($k).+ } |
2109 | ) |
2110 | ); |
2111 | ($($arg:tt)+) => ( |
2112 | $crate::event!( |
2113 | target: module_path!(), |
2114 | $crate::Level::INFO, |
2115 | {}, |
2116 | $($arg)+ |
2117 | ) |
2118 | ); |
2119 | } |
2120 | |
2121 | /// Constructs an event at the warn level. |
2122 | /// |
2123 | /// This functions similarly to the [`event!`] macro. See [the top-level |
2124 | /// documentation][lib] for details on the syntax accepted by |
2125 | /// this macro. |
2126 | /// |
2127 | /// [`event!`]: crate::event! |
2128 | /// [lib]: crate#using-the-macros |
2129 | /// |
2130 | /// # Examples |
2131 | /// |
2132 | /// ```rust |
2133 | /// use tracing::warn; |
2134 | /// # fn main() { |
2135 | /// |
2136 | /// let warn_description = "Invalid Input" ; |
2137 | /// let input = &[0x27, 0x45]; |
2138 | /// |
2139 | /// warn!(?input, warning = warn_description); |
2140 | /// warn!( |
2141 | /// target: "input_events" , |
2142 | /// warning = warn_description, |
2143 | /// "Received warning for input: {:?}" , input, |
2144 | /// ); |
2145 | /// warn!(name: "invalid" , ?input); |
2146 | /// # } |
2147 | /// ``` |
2148 | #[macro_export ] |
2149 | macro_rules! warn { |
2150 | // Name / target / parent. |
2151 | (name: $name:expr, target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
2152 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::WARN, { $($field)* }, $($arg)*) |
2153 | ); |
2154 | (name: $name:expr, target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
2155 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) |
2156 | ); |
2157 | (name: $name:expr, target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
2158 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) |
2159 | ); |
2160 | (name: $name:expr, target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
2161 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) |
2162 | ); |
2163 | (name: $name:expr, target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
2164 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::WARN, {}, $($arg)+) |
2165 | ); |
2166 | |
2167 | // Name / target. |
2168 | (name: $name:expr, target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
2169 | $crate::event!(name: $name, target: $target, $crate::Level::WARN, { $($field)* }, $($arg)*) |
2170 | ); |
2171 | (name: $name:expr, target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( |
2172 | $crate::event!(name: $name, target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) |
2173 | ); |
2174 | (name: $name:expr, target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
2175 | $crate::event!(name: $name, target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) |
2176 | ); |
2177 | (name: $name:expr, target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
2178 | $crate::event!(name: $name, target: $target, $crate::Level::WARN, { $($k).+ $($field)+ }) |
2179 | ); |
2180 | (name: $name:expr, target: $target:expr, $($arg:tt)+ ) => ( |
2181 | $crate::event!(name: $name, target: $target, $crate::Level::WARN, {}, $($arg)+) |
2182 | ); |
2183 | |
2184 | // Target / parent. |
2185 | (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
2186 | $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($field)* }, $($arg)*) |
2187 | ); |
2188 | (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
2189 | $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) |
2190 | ); |
2191 | (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
2192 | $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) |
2193 | ); |
2194 | (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
2195 | $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) |
2196 | ); |
2197 | (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
2198 | $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, {}, $($arg)+) |
2199 | ); |
2200 | |
2201 | // Name / parent. |
2202 | (name: $name:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
2203 | $crate::event!(name: $name, parent: $parent, $crate::Level::WARN, { $($field)* }, $($arg)*) |
2204 | ); |
2205 | (name: $name:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
2206 | $crate::event!(name: $name, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) |
2207 | ); |
2208 | (name: $name:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
2209 | $crate::event!(name: $name, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) |
2210 | ); |
2211 | (name: $name:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
2212 | $crate::event!(name: $name, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) |
2213 | ); |
2214 | (name: $name:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
2215 | $crate::event!(name: $name, parent: $parent, $crate::Level::WARN, {}, $($arg)+) |
2216 | ); |
2217 | |
2218 | // Name. |
2219 | (name: $name:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
2220 | $crate::event!(name: $name, $crate::Level::WARN, { $($field)* }, $($arg)*) |
2221 | ); |
2222 | (name: $name:expr, $($k:ident).+ $($field:tt)* ) => ( |
2223 | $crate::event!(name: $name, $crate::Level::WARN, { $($k).+ $($field)* }) |
2224 | ); |
2225 | (name: $name:expr, ?$($k:ident).+ $($field:tt)* ) => ( |
2226 | $crate::event!(name: $name, $crate::Level::WARN, { ?$($k).+ $($field)* }) |
2227 | ); |
2228 | (name: $name:expr, %$($k:ident).+ $($field:tt)* ) => ( |
2229 | $crate::event!(name: $name, $crate::Level::WARN, { %$($k).+ $($field)* }) |
2230 | ); |
2231 | (name: $name:expr, $($arg:tt)+ ) => ( |
2232 | $crate::event!(name: $name, $crate::Level::WARN, {}, $($arg)+) |
2233 | ); |
2234 | |
2235 | // Target. |
2236 | (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
2237 | $crate::event!(target: $target, $crate::Level::WARN, { $($field)* }, $($arg)*) |
2238 | ); |
2239 | (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( |
2240 | $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)* }) |
2241 | ); |
2242 | (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( |
2243 | $crate::event!(target: $target, $crate::Level::WARN, { ?$($k).+ $($field)* }) |
2244 | ); |
2245 | (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( |
2246 | $crate::event!(target: $target, $crate::Level::WARN, { %$($k).+ $($field)* }) |
2247 | ); |
2248 | (target: $target:expr, $($arg:tt)+ ) => ( |
2249 | $crate::event!(target: $target, $crate::Level::WARN, {}, $($arg)+) |
2250 | ); |
2251 | |
2252 | // Parent. |
2253 | (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( |
2254 | $crate::event!( |
2255 | target: module_path!(), |
2256 | parent: $parent, |
2257 | $crate::Level::WARN, |
2258 | { $($field)+ }, |
2259 | $($arg)+ |
2260 | ) |
2261 | ); |
2262 | (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( |
2263 | $crate::event!( |
2264 | target: module_path!(), |
2265 | parent: $parent, |
2266 | $crate::Level::WARN, |
2267 | { $($k).+ = $($field)*} |
2268 | ) |
2269 | ); |
2270 | (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( |
2271 | $crate::event!( |
2272 | target: module_path!(), |
2273 | parent: $parent, |
2274 | $crate::Level::WARN, |
2275 | { ?$($k).+ = $($field)*} |
2276 | ) |
2277 | ); |
2278 | (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( |
2279 | $crate::event!( |
2280 | target: module_path!(), |
2281 | parent: $parent, |
2282 | $crate::Level::WARN, |
2283 | { %$($k).+ = $($field)*} |
2284 | ) |
2285 | ); |
2286 | (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( |
2287 | $crate::event!( |
2288 | target: module_path!(), |
2289 | parent: $parent, |
2290 | $crate::Level::WARN, |
2291 | { $($k).+, $($field)*} |
2292 | ) |
2293 | ); |
2294 | (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( |
2295 | $crate::event!( |
2296 | target: module_path!(), |
2297 | parent: $parent, |
2298 | $crate::Level::WARN, |
2299 | { ?$($k).+, $($field)*} |
2300 | ) |
2301 | ); |
2302 | (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( |
2303 | $crate::event!( |
2304 | target: module_path!(), |
2305 | parent: $parent, |
2306 | $crate::Level::WARN, |
2307 | { %$($k).+, $($field)*} |
2308 | ) |
2309 | ); |
2310 | (parent: $parent:expr, $($arg:tt)+) => ( |
2311 | $crate::event!( |
2312 | target: module_path!(), |
2313 | parent: $parent, |
2314 | $crate::Level::WARN, |
2315 | {}, |
2316 | $($arg)+ |
2317 | ) |
2318 | ); |
2319 | |
2320 | // ... |
2321 | ({ $($field:tt)+ }, $($arg:tt)+ ) => ( |
2322 | $crate::event!( |
2323 | target: module_path!(), |
2324 | $crate::Level::WARN, |
2325 | { $($field)+ }, |
2326 | $($arg)+ |
2327 | ) |
2328 | ); |
2329 | ($($k:ident).+ = $($field:tt)*) => ( |
2330 | $crate::event!( |
2331 | target: module_path!(), |
2332 | $crate::Level::WARN, |
2333 | { $($k).+ = $($field)*} |
2334 | ) |
2335 | ); |
2336 | (?$($k:ident).+ = $($field:tt)*) => ( |
2337 | $crate::event!( |
2338 | target: module_path!(), |
2339 | $crate::Level::WARN, |
2340 | { ?$($k).+ = $($field)*} |
2341 | ) |
2342 | ); |
2343 | (%$($k:ident).+ = $($field:tt)*) => ( |
2344 | $crate::event!( |
2345 | target: module_path!(), |
2346 | $crate::Level::WARN, |
2347 | { %$($k).+ = $($field)*} |
2348 | ) |
2349 | ); |
2350 | ($($k:ident).+, $($field:tt)*) => ( |
2351 | $crate::event!( |
2352 | target: module_path!(), |
2353 | $crate::Level::WARN, |
2354 | { $($k).+, $($field)*} |
2355 | ) |
2356 | ); |
2357 | (?$($k:ident).+, $($field:tt)*) => ( |
2358 | $crate::event!( |
2359 | target: module_path!(), |
2360 | $crate::Level::WARN, |
2361 | { ?$($k).+, $($field)*} |
2362 | ) |
2363 | ); |
2364 | (%$($k:ident).+, $($field:tt)*) => ( |
2365 | $crate::event!( |
2366 | target: module_path!(), |
2367 | $crate::Level::WARN, |
2368 | { %$($k).+, $($field)*} |
2369 | ) |
2370 | ); |
2371 | (?$($k:ident).+) => ( |
2372 | $crate::event!( |
2373 | target: module_path!(), |
2374 | $crate::Level::WARN, |
2375 | { ?$($k).+ } |
2376 | ) |
2377 | ); |
2378 | (%$($k:ident).+) => ( |
2379 | $crate::event!( |
2380 | target: module_path!(), |
2381 | $crate::Level::WARN, |
2382 | { %$($k).+ } |
2383 | ) |
2384 | ); |
2385 | ($($k:ident).+) => ( |
2386 | $crate::event!( |
2387 | target: module_path!(), |
2388 | $crate::Level::WARN, |
2389 | { $($k).+ } |
2390 | ) |
2391 | ); |
2392 | ($($arg:tt)+) => ( |
2393 | $crate::event!( |
2394 | target: module_path!(), |
2395 | $crate::Level::WARN, |
2396 | {}, |
2397 | $($arg)+ |
2398 | ) |
2399 | ); |
2400 | } |
2401 | |
2402 | /// Constructs an event at the error level. |
2403 | /// |
2404 | /// This functions similarly to the [`event!`] macro. See [the top-level |
2405 | /// documentation][lib] for details on the syntax accepted by |
2406 | /// this macro. |
2407 | /// |
2408 | /// [`event!`]: crate::event! |
2409 | /// [lib]: crate#using-the-macros |
2410 | /// |
2411 | /// # Examples |
2412 | /// |
2413 | /// ```rust |
2414 | /// use tracing::error; |
2415 | /// # fn main() { |
2416 | /// |
2417 | /// let (err_info, port) = ("No connection" , 22); |
2418 | /// |
2419 | /// error!(port, error = %err_info); |
2420 | /// error!(target: "app_events" , "App Error: {}" , err_info); |
2421 | /// error!({ info = err_info }, "error on port: {}" , port); |
2422 | /// error!(name: "invalid_input" , "Invalid input: {}" , err_info); |
2423 | /// # } |
2424 | /// ``` |
2425 | #[macro_export ] |
2426 | macro_rules! error { |
2427 | // Name / target / parent. |
2428 | (name: $name:expr, target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
2429 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::ERROR, { $($field)* }, $($arg)*) |
2430 | ); |
2431 | (name: $name:expr, target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
2432 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) |
2433 | ); |
2434 | (name: $name:expr, target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
2435 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) |
2436 | ); |
2437 | (name: $name:expr, target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
2438 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) |
2439 | ); |
2440 | (name: $name:expr, target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
2441 | $crate::event!(name: $name, target: $target, parent: $parent, $crate::Level::ERROR, {}, $($arg)+) |
2442 | ); |
2443 | |
2444 | // Name / target. |
2445 | (name: $name:expr, target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
2446 | $crate::event!(name: $name, target: $target, $crate::Level::ERROR, { $($field)* }, $($arg)*) |
2447 | ); |
2448 | (name: $name:expr, target: $target:expr, $($k:ident).+ $($field:tt)+ ) => ( |
2449 | $crate::event!(name: $name, target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) |
2450 | ); |
2451 | (name: $name:expr, target: $target:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
2452 | $crate::event!(name: $name, target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) |
2453 | ); |
2454 | (name: $name:expr, target: $target:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
2455 | $crate::event!(name: $name, target: $target, $crate::Level::ERROR, { $($k).+ $($field)+ }) |
2456 | ); |
2457 | (name: $name:expr, target: $target:expr, $($arg:tt)+ ) => ( |
2458 | $crate::event!(name: $name, target: $target, $crate::Level::ERROR, {}, $($arg)+) |
2459 | ); |
2460 | |
2461 | // Target / parent. |
2462 | (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
2463 | $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($field)* }, $($arg)*) |
2464 | ); |
2465 | (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
2466 | $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) |
2467 | ); |
2468 | (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
2469 | $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) |
2470 | ); |
2471 | (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
2472 | $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) |
2473 | ); |
2474 | (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
2475 | $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, {}, $($arg)+) |
2476 | ); |
2477 | |
2478 | // Name / parent. |
2479 | (name: $name:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
2480 | $crate::event!(name: $name, parent: $parent, $crate::Level::ERROR, { $($field)* }, $($arg)*) |
2481 | ); |
2482 | (name: $name:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
2483 | $crate::event!(name: $name, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) |
2484 | ); |
2485 | (name: $name:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
2486 | $crate::event!(name: $name, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) |
2487 | ); |
2488 | (name: $name:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
2489 | $crate::event!(name: $name, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) |
2490 | ); |
2491 | (name: $name:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
2492 | $crate::event!(name: $name, parent: $parent, $crate::Level::ERROR, {}, $($arg)+) |
2493 | ); |
2494 | |
2495 | // Name. |
2496 | (name: $name:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
2497 | $crate::event!(name: $name, $crate::Level::ERROR, { $($field)* }, $($arg)*) |
2498 | ); |
2499 | (name: $name:expr, $($k:ident).+ $($field:tt)* ) => ( |
2500 | $crate::event!(name: $name, $crate::Level::ERROR, { $($k).+ $($field)* }) |
2501 | ); |
2502 | (name: $name:expr, ?$($k:ident).+ $($field:tt)* ) => ( |
2503 | $crate::event!(name: $name, $crate::Level::ERROR, { ?$($k).+ $($field)* }) |
2504 | ); |
2505 | (name: $name:expr, %$($k:ident).+ $($field:tt)* ) => ( |
2506 | $crate::event!(name: $name, $crate::Level::ERROR, { %$($k).+ $($field)* }) |
2507 | ); |
2508 | (name: $name:expr, $($arg:tt)+ ) => ( |
2509 | $crate::event!(name: $name, $crate::Level::ERROR, {}, $($arg)+) |
2510 | ); |
2511 | |
2512 | // Target. |
2513 | (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
2514 | $crate::event!(target: $target, $crate::Level::ERROR, { $($field)* }, $($arg)*) |
2515 | ); |
2516 | (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( |
2517 | $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)* }) |
2518 | ); |
2519 | (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( |
2520 | $crate::event!(target: $target, $crate::Level::ERROR, { ?$($k).+ $($field)* }) |
2521 | ); |
2522 | (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( |
2523 | $crate::event!(target: $target, $crate::Level::ERROR, { %$($k).+ $($field)* }) |
2524 | ); |
2525 | (target: $target:expr, $($arg:tt)+ ) => ( |
2526 | $crate::event!(target: $target, $crate::Level::ERROR, {}, $($arg)+) |
2527 | ); |
2528 | |
2529 | // Parent. |
2530 | (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( |
2531 | $crate::event!( |
2532 | target: module_path!(), |
2533 | parent: $parent, |
2534 | $crate::Level::ERROR, |
2535 | { $($field)+ }, |
2536 | $($arg)+ |
2537 | ) |
2538 | ); |
2539 | (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( |
2540 | $crate::event!( |
2541 | target: module_path!(), |
2542 | parent: $parent, |
2543 | $crate::Level::ERROR, |
2544 | { $($k).+ = $($field)*} |
2545 | ) |
2546 | ); |
2547 | (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( |
2548 | $crate::event!( |
2549 | target: module_path!(), |
2550 | parent: $parent, |
2551 | $crate::Level::ERROR, |
2552 | { ?$($k).+ = $($field)*} |
2553 | ) |
2554 | ); |
2555 | (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( |
2556 | $crate::event!( |
2557 | target: module_path!(), |
2558 | parent: $parent, |
2559 | $crate::Level::ERROR, |
2560 | { %$($k).+ = $($field)*} |
2561 | ) |
2562 | ); |
2563 | (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( |
2564 | $crate::event!( |
2565 | target: module_path!(), |
2566 | parent: $parent, |
2567 | $crate::Level::ERROR, |
2568 | { $($k).+, $($field)*} |
2569 | ) |
2570 | ); |
2571 | (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( |
2572 | $crate::event!( |
2573 | target: module_path!(), |
2574 | parent: $parent, |
2575 | $crate::Level::ERROR, |
2576 | { ?$($k).+, $($field)*} |
2577 | ) |
2578 | ); |
2579 | (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( |
2580 | $crate::event!( |
2581 | target: module_path!(), |
2582 | parent: $parent, |
2583 | $crate::Level::ERROR, |
2584 | { %$($k).+, $($field)*} |
2585 | ) |
2586 | ); |
2587 | (parent: $parent:expr, $($arg:tt)+) => ( |
2588 | $crate::event!( |
2589 | target: module_path!(), |
2590 | parent: $parent, |
2591 | $crate::Level::ERROR, |
2592 | {}, |
2593 | $($arg)+ |
2594 | ) |
2595 | ); |
2596 | |
2597 | // ... |
2598 | ({ $($field:tt)+ }, $($arg:tt)+ ) => ( |
2599 | $crate::event!( |
2600 | target: module_path!(), |
2601 | $crate::Level::ERROR, |
2602 | { $($field)+ }, |
2603 | $($arg)+ |
2604 | ) |
2605 | ); |
2606 | ($($k:ident).+ = $($field:tt)*) => ( |
2607 | $crate::event!( |
2608 | target: module_path!(), |
2609 | $crate::Level::ERROR, |
2610 | { $($k).+ = $($field)*} |
2611 | ) |
2612 | ); |
2613 | (?$($k:ident).+ = $($field:tt)*) => ( |
2614 | $crate::event!( |
2615 | target: module_path!(), |
2616 | $crate::Level::ERROR, |
2617 | { ?$($k).+ = $($field)*} |
2618 | ) |
2619 | ); |
2620 | (%$($k:ident).+ = $($field:tt)*) => ( |
2621 | $crate::event!( |
2622 | target: module_path!(), |
2623 | $crate::Level::ERROR, |
2624 | { %$($k).+ = $($field)*} |
2625 | ) |
2626 | ); |
2627 | ($($k:ident).+, $($field:tt)*) => ( |
2628 | $crate::event!( |
2629 | target: module_path!(), |
2630 | $crate::Level::ERROR, |
2631 | { $($k).+, $($field)*} |
2632 | ) |
2633 | ); |
2634 | (?$($k:ident).+, $($field:tt)*) => ( |
2635 | $crate::event!( |
2636 | target: module_path!(), |
2637 | $crate::Level::ERROR, |
2638 | { ?$($k).+, $($field)*} |
2639 | ) |
2640 | ); |
2641 | (%$($k:ident).+, $($field:tt)*) => ( |
2642 | $crate::event!( |
2643 | target: module_path!(), |
2644 | $crate::Level::ERROR, |
2645 | { %$($k).+, $($field)*} |
2646 | ) |
2647 | ); |
2648 | (?$($k:ident).+) => ( |
2649 | $crate::event!( |
2650 | target: module_path!(), |
2651 | $crate::Level::ERROR, |
2652 | { ?$($k).+ } |
2653 | ) |
2654 | ); |
2655 | (%$($k:ident).+) => ( |
2656 | $crate::event!( |
2657 | target: module_path!(), |
2658 | $crate::Level::ERROR, |
2659 | { %$($k).+ } |
2660 | ) |
2661 | ); |
2662 | ($($k:ident).+) => ( |
2663 | $crate::event!( |
2664 | target: module_path!(), |
2665 | $crate::Level::ERROR, |
2666 | { $($k).+ } |
2667 | ) |
2668 | ); |
2669 | ($($arg:tt)+) => ( |
2670 | $crate::event!( |
2671 | target: module_path!(), |
2672 | $crate::Level::ERROR, |
2673 | {}, |
2674 | $($arg)+ |
2675 | ) |
2676 | ); |
2677 | } |
2678 | |
2679 | /// Constructs a new static callsite for a span or event. |
2680 | #[doc (hidden)] |
2681 | #[macro_export ] |
2682 | macro_rules! callsite { |
2683 | (name: $name:expr, kind: $kind:expr, fields: $($fields:tt)*) => {{ |
2684 | $crate::callsite! { |
2685 | name: $name, |
2686 | kind: $kind, |
2687 | target: module_path!(), |
2688 | level: $crate::Level::TRACE, |
2689 | fields: $($fields)* |
2690 | } |
2691 | }}; |
2692 | ( |
2693 | name: $name:expr, |
2694 | kind: $kind:expr, |
2695 | level: $lvl:expr, |
2696 | fields: $($fields:tt)* |
2697 | ) => {{ |
2698 | $crate::callsite! { |
2699 | name: $name, |
2700 | kind: $kind, |
2701 | target: module_path!(), |
2702 | level: $lvl, |
2703 | fields: $($fields)* |
2704 | } |
2705 | }}; |
2706 | ( |
2707 | name: $name:expr, |
2708 | kind: $kind:expr, |
2709 | target: $target:expr, |
2710 | level: $lvl:expr, |
2711 | fields: $($fields:tt)* |
2712 | ) => {{ |
2713 | static META: $crate::Metadata<'static> = { |
2714 | $crate::metadata! { |
2715 | name: $name, |
2716 | target: $target, |
2717 | level: $lvl, |
2718 | fields: $crate::fieldset!( $($fields)* ), |
2719 | callsite: &__CALLSITE, |
2720 | kind: $kind, |
2721 | } |
2722 | }; |
2723 | static __CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite::DefaultCallsite::new(&META); |
2724 | __CALLSITE.register(); |
2725 | &__CALLSITE |
2726 | }}; |
2727 | } |
2728 | |
2729 | /// Constructs a new static callsite for a span or event. |
2730 | #[doc (hidden)] |
2731 | #[macro_export ] |
2732 | macro_rules! callsite2 { |
2733 | (name: $name:expr, kind: $kind:expr, fields: $($fields:tt)*) => {{ |
2734 | $crate::callsite2! { |
2735 | name: $name, |
2736 | kind: $kind, |
2737 | target: module_path!(), |
2738 | level: $crate::Level::TRACE, |
2739 | fields: $($fields)* |
2740 | } |
2741 | }}; |
2742 | ( |
2743 | name: $name:expr, |
2744 | kind: $kind:expr, |
2745 | level: $lvl:expr, |
2746 | fields: $($fields:tt)* |
2747 | ) => {{ |
2748 | $crate::callsite2! { |
2749 | name: $name, |
2750 | kind: $kind, |
2751 | target: module_path!(), |
2752 | level: $lvl, |
2753 | fields: $($fields)* |
2754 | } |
2755 | }}; |
2756 | ( |
2757 | name: $name:expr, |
2758 | kind: $kind:expr, |
2759 | target: $target:expr, |
2760 | level: $lvl:expr, |
2761 | fields: $($fields:tt)* |
2762 | ) => {{ |
2763 | static META: $crate::Metadata<'static> = { |
2764 | $crate::metadata! { |
2765 | name: $name, |
2766 | target: $target, |
2767 | level: $lvl, |
2768 | fields: $crate::fieldset!( $($fields)* ), |
2769 | callsite: &__CALLSITE, |
2770 | kind: $kind, |
2771 | } |
2772 | }; |
2773 | $crate::callsite::DefaultCallsite::new(&META) |
2774 | }}; |
2775 | } |
2776 | |
2777 | #[macro_export ] |
2778 | // TODO: determine if this ought to be public API?` |
2779 | #[doc (hidden)] |
2780 | macro_rules! level_enabled { |
2781 | ($lvl:expr) => { |
2782 | $lvl <= $crate::level_filters::STATIC_MAX_LEVEL |
2783 | && $lvl <= $crate::level_filters::LevelFilter::current() |
2784 | }; |
2785 | } |
2786 | |
2787 | #[doc (hidden)] |
2788 | #[macro_export ] |
2789 | macro_rules! valueset { |
2790 | |
2791 | // === base case === |
2792 | (@ { $(,)* $($val:expr),* $(,)* }, $next:expr $(,)*) => { |
2793 | &[ $($val),* ] |
2794 | }; |
2795 | |
2796 | // === recursive case (more tts) === |
2797 | |
2798 | // TODO(#1138): determine a new syntax for uninitialized span fields, and |
2799 | // re-enable this. |
2800 | // (@{ $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = _, $($rest:tt)*) => { |
2801 | // $crate::valueset!(@ { $($out),*, (&$next, None) }, $next, $($rest)*) |
2802 | // }; |
2803 | (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { |
2804 | $crate::valueset!( |
2805 | @ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$val) as &dyn Value)) }, |
2806 | $next, |
2807 | $($rest)* |
2808 | ) |
2809 | }; |
2810 | (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr, $($rest:tt)*) => { |
2811 | $crate::valueset!( |
2812 | @ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$val) as &dyn Value)) }, |
2813 | $next, |
2814 | $($rest)* |
2815 | ) |
2816 | }; |
2817 | (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr, $($rest:tt)*) => { |
2818 | $crate::valueset!( |
2819 | @ { $($out),*, (&$next, ::core::option::Option::Some(&$val as &dyn Value)) }, |
2820 | $next, |
2821 | $($rest)* |
2822 | ) |
2823 | }; |
2824 | (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+, $($rest:tt)*) => { |
2825 | $crate::valueset!( |
2826 | @ { $($out),*, (&$next, ::core::option::Option::Some(&$($k).+ as &dyn Value)) }, |
2827 | $next, |
2828 | $($rest)* |
2829 | ) |
2830 | }; |
2831 | (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+, $($rest:tt)*) => { |
2832 | $crate::valueset!( |
2833 | @ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$($k).+) as &dyn Value)) }, |
2834 | $next, |
2835 | $($rest)* |
2836 | ) |
2837 | }; |
2838 | (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+, $($rest:tt)*) => { |
2839 | $crate::valueset!( |
2840 | @ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$($k).+) as &dyn Value)) }, |
2841 | $next, |
2842 | $($rest)* |
2843 | ) |
2844 | }; |
2845 | (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr) => { |
2846 | $crate::valueset!( |
2847 | @ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$val) as &dyn Value)) }, |
2848 | $next, |
2849 | ) |
2850 | }; |
2851 | (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr) => { |
2852 | $crate::valueset!( |
2853 | @ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$val) as &dyn Value)) }, |
2854 | $next, |
2855 | ) |
2856 | }; |
2857 | (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr) => { |
2858 | $crate::valueset!( |
2859 | @ { $($out),*, (&$next, ::core::option::Option::Some(&$val as &dyn Value)) }, |
2860 | $next, |
2861 | ) |
2862 | }; |
2863 | (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+) => { |
2864 | $crate::valueset!( |
2865 | @ { $($out),*, (&$next, ::core::option::Option::Some(&$($k).+ as &dyn Value)) }, |
2866 | $next, |
2867 | ) |
2868 | }; |
2869 | (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+) => { |
2870 | $crate::valueset!( |
2871 | @ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$($k).+) as &dyn Value)) }, |
2872 | $next, |
2873 | ) |
2874 | }; |
2875 | (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+) => { |
2876 | $crate::valueset!( |
2877 | @ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$($k).+) as &dyn Value)) }, |
2878 | $next, |
2879 | ) |
2880 | }; |
2881 | |
2882 | // Handle literal names |
2883 | (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = ?$val:expr, $($rest:tt)*) => { |
2884 | $crate::valueset!( |
2885 | @ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$val) as &dyn Value)) }, |
2886 | $next, |
2887 | $($rest)* |
2888 | ) |
2889 | }; |
2890 | (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = %$val:expr, $($rest:tt)*) => { |
2891 | $crate::valueset!( |
2892 | @ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$val) as &dyn Value)) }, |
2893 | $next, |
2894 | $($rest)* |
2895 | ) |
2896 | }; |
2897 | (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = $val:expr, $($rest:tt)*) => { |
2898 | $crate::valueset!( |
2899 | @ { $($out),*, (&$next, ::core::option::Option::Some(&$val as &dyn Value)) }, |
2900 | $next, |
2901 | $($rest)* |
2902 | ) |
2903 | }; |
2904 | (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = ?$val:expr) => { |
2905 | $crate::valueset!( |
2906 | @ { $($out),*, (&$next, ::core::option::Option::Some(&debug(&$val) as &dyn Value)) }, |
2907 | $next, |
2908 | ) |
2909 | }; |
2910 | (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = %$val:expr) => { |
2911 | $crate::valueset!( |
2912 | @ { $($out),*, (&$next, ::core::option::Option::Some(&display(&$val) as &dyn Value)) }, |
2913 | $next, |
2914 | ) |
2915 | }; |
2916 | (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = $val:expr) => { |
2917 | $crate::valueset!( |
2918 | @ { $($out),*, (&$next, ::core::option::Option::Some(&$val as &dyn Value)) }, |
2919 | $next, |
2920 | ) |
2921 | }; |
2922 | |
2923 | // Handle constant names |
2924 | (@ { $(,)* $($out:expr),* }, $next:expr, { $k:expr } = ?$val:expr, $($rest:tt)*) => { |
2925 | $crate::valueset!( |
2926 | @ { $($out),*, (&$next, Some(&debug(&$val) as &dyn Value)) }, |
2927 | $next, |
2928 | $($rest)* |
2929 | ) |
2930 | }; |
2931 | (@ { $(,)* $($out:expr),* }, $next:expr, { $k:expr } = %$val:expr, $($rest:tt)*) => { |
2932 | $crate::valueset!( |
2933 | @ { $($out),*, (&$next, Some(&display(&$val) as &dyn Value)) }, |
2934 | $next, |
2935 | $($rest)* |
2936 | ) |
2937 | }; |
2938 | (@ { $(,)* $($out:expr),* }, $next:expr, { $k:expr } = $val:expr, $($rest:tt)*) => { |
2939 | $crate::valueset!( |
2940 | @ { $($out),*, (&$next, Some(&$val as &dyn Value)) }, |
2941 | $next, |
2942 | $($rest)* |
2943 | ) |
2944 | }; |
2945 | (@ { $(,)* $($out:expr),* }, $next:expr, { $k:expr } = ?$val:expr) => { |
2946 | $crate::valueset!( |
2947 | @ { $($out),*, (&$next, Some(&debug(&$val) as &dyn Value)) }, |
2948 | $next, |
2949 | ) |
2950 | }; |
2951 | (@ { $(,)* $($out:expr),* }, $next:expr, { $k:expr } = %$val:expr) => { |
2952 | $crate::valueset!( |
2953 | @ { $($out),*, (&$next, Some(&display(&$val) as &dyn Value)) }, |
2954 | $next, |
2955 | ) |
2956 | }; |
2957 | (@ { $(,)* $($out:expr),* }, $next:expr, { $k:expr } = $val:expr) => { |
2958 | $crate::valueset!( |
2959 | @ { $($out),*, (&$next, Some(&$val as &dyn Value)) }, |
2960 | $next, |
2961 | ) |
2962 | }; |
2963 | |
2964 | // Remainder is unparsable, but exists --- must be format args! |
2965 | (@ { $(,)* $($out:expr),* }, $next:expr, $($rest:tt)+) => { |
2966 | $crate::valueset!(@ { (&$next, ::core::option::Option::Some(&::core::format_args!($($rest)+) as &dyn Value)), $($out),* }, $next, ) |
2967 | }; |
2968 | |
2969 | // === entry === |
2970 | ($fields:expr, $($kvs:tt)+) => { |
2971 | { |
2972 | #[allow(unused_imports)] |
2973 | use $crate::field::{debug, display, Value}; |
2974 | let mut iter = $fields.iter(); |
2975 | $fields.value_set($crate::valueset!( |
2976 | @ { }, |
2977 | ::core::iter::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)" ), |
2978 | $($kvs)+ |
2979 | )) |
2980 | } |
2981 | }; |
2982 | ($fields:expr,) => { |
2983 | { |
2984 | $fields.value_set(&[]) |
2985 | } |
2986 | }; |
2987 | } |
2988 | |
2989 | #[doc (hidden)] |
2990 | #[macro_export ] |
2991 | macro_rules! fieldset { |
2992 | // == base case == |
2993 | (@ { $(,)* $($out:expr),* $(,)* } $(,)*) => { |
2994 | &[ $($out),* ] |
2995 | }; |
2996 | |
2997 | // == recursive cases (more tts) == |
2998 | (@ { $(,)* $($out:expr),* } $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { |
2999 | $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) |
3000 | }; |
3001 | (@ { $(,)* $($out:expr),* } $($k:ident).+ = %$val:expr, $($rest:tt)*) => { |
3002 | $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) |
3003 | }; |
3004 | (@ { $(,)* $($out:expr),* } $($k:ident).+ = $val:expr, $($rest:tt)*) => { |
3005 | $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) |
3006 | }; |
3007 | // TODO(#1138): determine a new syntax for uninitialized span fields, and |
3008 | // re-enable this. |
3009 | // (@ { $($out:expr),* } $($k:ident).+ = _, $($rest:tt)*) => { |
3010 | // $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) |
3011 | // }; |
3012 | (@ { $(,)* $($out:expr),* } ?$($k:ident).+, $($rest:tt)*) => { |
3013 | $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) |
3014 | }; |
3015 | (@ { $(,)* $($out:expr),* } %$($k:ident).+, $($rest:tt)*) => { |
3016 | $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) |
3017 | }; |
3018 | (@ { $(,)* $($out:expr),* } $($k:ident).+, $($rest:tt)*) => { |
3019 | $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) |
3020 | }; |
3021 | |
3022 | // Handle literal names |
3023 | (@ { $(,)* $($out:expr),* } $k:literal = ?$val:expr, $($rest:tt)*) => { |
3024 | $crate::fieldset!(@ { $($out),*, $k } $($rest)*) |
3025 | }; |
3026 | (@ { $(,)* $($out:expr),* } $k:literal = %$val:expr, $($rest:tt)*) => { |
3027 | $crate::fieldset!(@ { $($out),*, $k } $($rest)*) |
3028 | }; |
3029 | (@ { $(,)* $($out:expr),* } $k:literal = $val:expr, $($rest:tt)*) => { |
3030 | $crate::fieldset!(@ { $($out),*, $k } $($rest)*) |
3031 | }; |
3032 | |
3033 | // Handle constant names |
3034 | (@ { $(,)* $($out:expr),* } { $k:expr } = ?$val:expr, $($rest:tt)*) => { |
3035 | $crate::fieldset!(@ { $($out),*, $k } $($rest)*) |
3036 | }; |
3037 | (@ { $(,)* $($out:expr),* } { $k:expr } = %$val:expr, $($rest:tt)*) => { |
3038 | $crate::fieldset!(@ { $($out),*, $k } $($rest)*) |
3039 | }; |
3040 | (@ { $(,)* $($out:expr),* } { $k:expr } = $val:expr, $($rest:tt)*) => { |
3041 | $crate::fieldset!(@ { $($out),*, $k } $($rest)*) |
3042 | }; |
3043 | |
3044 | // Remainder is unparseable, but exists --- must be format args! |
3045 | (@ { $(,)* $($out:expr),* } $($rest:tt)+) => { |
3046 | $crate::fieldset!(@ { "message" , $($out),*, }) |
3047 | }; |
3048 | |
3049 | // == entry == |
3050 | ($($args:tt)*) => { |
3051 | $crate::fieldset!(@ { } $($args)*,) |
3052 | }; |
3053 | |
3054 | } |
3055 | |
3056 | #[cfg (feature = "log" )] |
3057 | #[doc (hidden)] |
3058 | #[macro_export ] |
3059 | macro_rules! level_to_log { |
3060 | ($level:expr) => { |
3061 | match $level { |
3062 | $crate::Level::ERROR => $crate::log::Level::Error, |
3063 | $crate::Level::WARN => $crate::log::Level::Warn, |
3064 | $crate::Level::INFO => $crate::log::Level::Info, |
3065 | $crate::Level::DEBUG => $crate::log::Level::Debug, |
3066 | _ => $crate::log::Level::Trace, |
3067 | } |
3068 | }; |
3069 | } |
3070 | |
3071 | #[doc (hidden)] |
3072 | #[macro_export ] |
3073 | macro_rules! __tracing_stringify { |
3074 | ($s:expr) => { |
3075 | stringify!($s) |
3076 | }; |
3077 | } |
3078 | |
3079 | #[cfg (not(feature = "log" ))] |
3080 | #[doc (hidden)] |
3081 | #[macro_export ] |
3082 | macro_rules! __tracing_log { |
3083 | ($level:expr, $callsite:expr, $value_set:expr) => {}; |
3084 | } |
3085 | |
3086 | #[cfg (feature = "log" )] |
3087 | #[doc (hidden)] |
3088 | #[macro_export ] |
3089 | macro_rules! __tracing_log { |
3090 | ($level:expr, $callsite:expr, $value_set:expr) => { |
3091 | $crate::if_log_enabled! { $level, { |
3092 | use $crate::log; |
3093 | let level = $crate::level_to_log!($level); |
3094 | if level <= log::max_level() { |
3095 | let meta = $callsite.metadata(); |
3096 | let log_meta = log::Metadata::builder() |
3097 | .level(level) |
3098 | .target(meta.target()) |
3099 | .build(); |
3100 | let logger = log::logger(); |
3101 | if logger.enabled(&log_meta) { |
3102 | $crate::__macro_support::__tracing_log(meta, logger, log_meta, $value_set) |
3103 | } |
3104 | } |
3105 | }} |
3106 | }; |
3107 | } |
3108 | |
3109 | #[cfg (not(feature = "log" ))] |
3110 | #[doc (hidden)] |
3111 | #[macro_export ] |
3112 | macro_rules! if_log_enabled { |
3113 | ($lvl:expr, $e:expr;) => { |
3114 | $crate::if_log_enabled! { $lvl, $e } |
3115 | }; |
3116 | ($lvl:expr, $if_log:block) => { |
3117 | $crate::if_log_enabled! { $lvl, $if_log else {} } |
3118 | }; |
3119 | ($lvl:expr, $if_log:block else $else_block:block) => { |
3120 | $else_block |
3121 | }; |
3122 | } |
3123 | |
3124 | #[cfg (all(feature = "log" , not(feature = "log-always" )))] |
3125 | #[doc (hidden)] |
3126 | #[macro_export ] |
3127 | macro_rules! if_log_enabled { |
3128 | ($lvl:expr, $e:expr;) => { |
3129 | $crate::if_log_enabled! { $lvl, $e } |
3130 | }; |
3131 | ($lvl:expr, $if_log:block) => { |
3132 | $crate::if_log_enabled! { $lvl, $if_log else {} } |
3133 | }; |
3134 | ($lvl:expr, $if_log:block else $else_block:block) => { |
3135 | if $crate::level_to_log!($lvl) <= $crate::log::STATIC_MAX_LEVEL { |
3136 | if !$crate::dispatcher::has_been_set() { |
3137 | $if_log |
3138 | } else { |
3139 | $else_block |
3140 | } |
3141 | } else { |
3142 | $else_block |
3143 | } |
3144 | }; |
3145 | } |
3146 | |
3147 | #[cfg (all(feature = "log" , feature = "log-always" ))] |
3148 | #[doc (hidden)] |
3149 | #[macro_export ] |
3150 | macro_rules! if_log_enabled { |
3151 | ($lvl:expr, $e:expr;) => { |
3152 | $crate::if_log_enabled! { $lvl, $e } |
3153 | }; |
3154 | ($lvl:expr, $if_log:block) => { |
3155 | $crate::if_log_enabled! { $lvl, $if_log else {} } |
3156 | }; |
3157 | ($lvl:expr, $if_log:block else $else_block:block) => { |
3158 | if $crate::level_to_log!($lvl) <= $crate::log::STATIC_MAX_LEVEL { |
3159 | #[allow(unused_braces)] |
3160 | $if_log |
3161 | } else { |
3162 | $else_block |
3163 | } |
3164 | }; |
3165 | } |
3166 | |