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::callsite::DefaultCallsite = $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!(Level::INFO, the_answer = data.0); |
568 | /// # } |
569 | /// ``` |
570 | /// |
571 | // /// Note that *unlike `span!`*, `event!` requires a value for all fields. As |
572 | // /// events are recorded immediately when the macro is invoked, there is no |
573 | // /// opportunity for fields to be recorded later. A trailing comma on the final |
574 | // /// field is valid. |
575 | // /// |
576 | // /// For example, the following does not compile: |
577 | // /// ```rust,compile_fail |
578 | // /// # use tracing::{Level, event}; |
579 | // /// # fn main() { |
580 | // /// event!(Level::INFO, foo = 5, bad_field, bar = "hello") |
581 | // /// #} |
582 | // /// ``` |
583 | #[macro_export ] |
584 | macro_rules! event { |
585 | (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* } )=> ({ |
586 | use $crate::__macro_support::Callsite as _; |
587 | static CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite2! { |
588 | name: $crate::__macro_support::concat!( |
589 | "event " , |
590 | file!(), |
591 | ":" , |
592 | line!() |
593 | ), |
594 | kind: $crate::metadata::Kind::EVENT, |
595 | target: $target, |
596 | level: $lvl, |
597 | fields: $($fields)* |
598 | }; |
599 | |
600 | let enabled = $crate::level_enabled!($lvl) && { |
601 | let interest = CALLSITE.interest(); |
602 | !interest.is_never() && $crate::__macro_support::__is_enabled(CALLSITE.metadata(), interest) |
603 | }; |
604 | if enabled { |
605 | (|value_set: $crate::field::ValueSet| { |
606 | $crate::__tracing_log!( |
607 | $lvl, |
608 | CALLSITE, |
609 | &value_set |
610 | ); |
611 | let meta = CALLSITE.metadata(); |
612 | // event with explicit parent |
613 | $crate::Event::child_of( |
614 | $parent, |
615 | meta, |
616 | &value_set |
617 | ); |
618 | })($crate::valueset!(CALLSITE.metadata().fields(), $($fields)*)); |
619 | } else { |
620 | $crate::__tracing_log!( |
621 | $lvl, |
622 | CALLSITE, |
623 | &$crate::valueset!(CALLSITE.metadata().fields(), $($fields)*) |
624 | ); |
625 | } |
626 | }); |
627 | |
628 | (target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( |
629 | $crate::event!( |
630 | target: $target, |
631 | parent: $parent, |
632 | $lvl, |
633 | { message = format_args!($($arg)+), $($fields)* } |
634 | ) |
635 | ); |
636 | (target: $target:expr, parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( |
637 | $crate::event!(target: $target, parent: $parent, $lvl, { $($k).+ = $($fields)* }) |
638 | ); |
639 | (target: $target:expr, parent: $parent:expr, $lvl:expr, $($arg:tt)+) => ( |
640 | $crate::event!(target: $target, parent: $parent, $lvl, { $($arg)+ }) |
641 | ); |
642 | (target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ |
643 | use $crate::__macro_support::Callsite as _; |
644 | static CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite2! { |
645 | name: $crate::__macro_support::concat!( |
646 | "event " , |
647 | file!(), |
648 | ":" , |
649 | line!() |
650 | ), |
651 | kind: $crate::metadata::Kind::EVENT, |
652 | target: $target, |
653 | level: $lvl, |
654 | fields: $($fields)* |
655 | }; |
656 | let enabled = $crate::level_enabled!($lvl) && { |
657 | let interest = CALLSITE.interest(); |
658 | !interest.is_never() && $crate::__macro_support::__is_enabled(CALLSITE.metadata(), interest) |
659 | }; |
660 | if enabled { |
661 | (|value_set: $crate::field::ValueSet| { |
662 | let meta = CALLSITE.metadata(); |
663 | // event with contextual parent |
664 | $crate::Event::dispatch( |
665 | meta, |
666 | &value_set |
667 | ); |
668 | $crate::__tracing_log!( |
669 | $lvl, |
670 | CALLSITE, |
671 | &value_set |
672 | ); |
673 | })($crate::valueset!(CALLSITE.metadata().fields(), $($fields)*)); |
674 | } else { |
675 | $crate::__tracing_log!( |
676 | $lvl, |
677 | CALLSITE, |
678 | &$crate::valueset!(CALLSITE.metadata().fields(), $($fields)*) |
679 | ); |
680 | } |
681 | }); |
682 | (target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( |
683 | $crate::event!( |
684 | target: $target, |
685 | $lvl, |
686 | { message = format_args!($($arg)+), $($fields)* } |
687 | ) |
688 | ); |
689 | (target: $target:expr, $lvl:expr, $($k:ident).+ = $($fields:tt)* ) => ( |
690 | $crate::event!(target: $target, $lvl, { $($k).+ = $($fields)* }) |
691 | ); |
692 | (target: $target:expr, $lvl:expr, $($arg:tt)+ ) => ( |
693 | $crate::event!(target: $target, $lvl, { $($arg)+ }) |
694 | ); |
695 | (parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( |
696 | $crate::event!( |
697 | target: module_path!(), |
698 | parent: $parent, |
699 | $lvl, |
700 | { message = format_args!($($arg)+), $($fields)* } |
701 | ) |
702 | ); |
703 | (parent: $parent:expr, $lvl:expr, $($k:ident).+ = $($field:tt)*) => ( |
704 | $crate::event!( |
705 | target: module_path!(), |
706 | parent: $parent, |
707 | $lvl, |
708 | { $($k).+ = $($field)*} |
709 | ) |
710 | ); |
711 | (parent: $parent:expr, $lvl:expr, ?$($k:ident).+ = $($field:tt)*) => ( |
712 | $crate::event!( |
713 | target: module_path!(), |
714 | parent: $parent, |
715 | $lvl, |
716 | { ?$($k).+ = $($field)*} |
717 | ) |
718 | ); |
719 | (parent: $parent:expr, $lvl:expr, %$($k:ident).+ = $($field:tt)*) => ( |
720 | $crate::event!( |
721 | target: module_path!(), |
722 | parent: $parent, |
723 | $lvl, |
724 | { %$($k).+ = $($field)*} |
725 | ) |
726 | ); |
727 | (parent: $parent:expr, $lvl:expr, $($k:ident).+, $($field:tt)*) => ( |
728 | $crate::event!( |
729 | target: module_path!(), |
730 | parent: $parent, |
731 | $lvl, |
732 | { $($k).+, $($field)*} |
733 | ) |
734 | ); |
735 | (parent: $parent:expr, $lvl:expr, %$($k:ident).+, $($field:tt)*) => ( |
736 | $crate::event!( |
737 | target: module_path!(), |
738 | parent: $parent, |
739 | $lvl, |
740 | { %$($k).+, $($field)*} |
741 | ) |
742 | ); |
743 | (parent: $parent:expr, $lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( |
744 | $crate::event!( |
745 | target: module_path!(), |
746 | parent: $parent, |
747 | $lvl, |
748 | { ?$($k).+, $($field)*} |
749 | ) |
750 | ); |
751 | (parent: $parent:expr, $lvl:expr, $($arg:tt)+ ) => ( |
752 | $crate::event!(target: module_path!(), parent: $parent, $lvl, { $($arg)+ }) |
753 | ); |
754 | ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( |
755 | $crate::event!( |
756 | target: module_path!(), |
757 | $lvl, |
758 | { message = format_args!($($arg)+), $($fields)* } |
759 | ) |
760 | ); |
761 | ( $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( |
762 | $crate::event!( |
763 | target: module_path!(), |
764 | $lvl, |
765 | { message = format_args!($($arg)+), $($fields)* } |
766 | ) |
767 | ); |
768 | ($lvl:expr, $($k:ident).+ = $($field:tt)*) => ( |
769 | $crate::event!( |
770 | target: module_path!(), |
771 | $lvl, |
772 | { $($k).+ = $($field)*} |
773 | ) |
774 | ); |
775 | ($lvl:expr, $($k:ident).+, $($field:tt)*) => ( |
776 | $crate::event!( |
777 | target: module_path!(), |
778 | $lvl, |
779 | { $($k).+, $($field)*} |
780 | ) |
781 | ); |
782 | ($lvl:expr, ?$($k:ident).+, $($field:tt)*) => ( |
783 | $crate::event!( |
784 | target: module_path!(), |
785 | $lvl, |
786 | { ?$($k).+, $($field)*} |
787 | ) |
788 | ); |
789 | ($lvl:expr, %$($k:ident).+, $($field:tt)*) => ( |
790 | $crate::event!( |
791 | target: module_path!(), |
792 | $lvl, |
793 | { %$($k).+, $($field)*} |
794 | ) |
795 | ); |
796 | ($lvl:expr, ?$($k:ident).+) => ( |
797 | $crate::event!($lvl, ?$($k).+,) |
798 | ); |
799 | ($lvl:expr, %$($k:ident).+) => ( |
800 | $crate::event!($lvl, %$($k).+,) |
801 | ); |
802 | ($lvl:expr, $($k:ident).+) => ( |
803 | $crate::event!($lvl, $($k).+,) |
804 | ); |
805 | ( $lvl:expr, $($arg:tt)+ ) => ( |
806 | $crate::event!(target: module_path!(), $lvl, { $($arg)+ }) |
807 | ); |
808 | } |
809 | |
810 | /// Tests whether an event with the specified level and target would be enabled. |
811 | /// |
812 | /// This is similar to [`enabled!`], but queries the current subscriber specifically for |
813 | /// an event, whereas [`enabled!`] queries for an event _or_ span. |
814 | /// |
815 | /// See the documentation for [`enabled!]` for more details on using this macro. |
816 | /// See also [`span_enabled!`]. |
817 | /// |
818 | /// # Examples |
819 | /// |
820 | /// ```rust |
821 | /// # use tracing::{event_enabled, Level}; |
822 | /// if event_enabled!(target: "my_crate" , Level::DEBUG) { |
823 | /// // some expensive work... |
824 | /// } |
825 | /// // simpler |
826 | /// if event_enabled!(Level::DEBUG) { |
827 | /// // some expensive work... |
828 | /// } |
829 | /// // with fields |
830 | /// if event_enabled!(Level::DEBUG, foo_field) { |
831 | /// // some expensive work... |
832 | /// } |
833 | /// ``` |
834 | /// |
835 | /// [`enabled!`]: crate::enabled |
836 | /// [`span_enabled!`]: crate::span_enabled |
837 | #[macro_export ] |
838 | macro_rules! event_enabled { |
839 | ($($rest:tt)*)=> ( |
840 | $crate::enabled!(kind: $crate::metadata::Kind::EVENT, $($rest)*) |
841 | ) |
842 | } |
843 | |
844 | /// Tests whether a span with the specified level and target would be enabled. |
845 | /// |
846 | /// This is similar to [`enabled!`], but queries the current subscriber specifically for |
847 | /// an event, whereas [`enabled!`] queries for an event _or_ span. |
848 | /// |
849 | /// See the documentation for [`enabled!]` for more details on using this macro. |
850 | /// See also [`span_enabled!`]. |
851 | /// |
852 | /// # Examples |
853 | /// |
854 | /// ```rust |
855 | /// # use tracing::{span_enabled, Level}; |
856 | /// if span_enabled!(target: "my_crate" , Level::DEBUG) { |
857 | /// // some expensive work... |
858 | /// } |
859 | /// // simpler |
860 | /// if span_enabled!(Level::DEBUG) { |
861 | /// // some expensive work... |
862 | /// } |
863 | /// // with fields |
864 | /// if span_enabled!(Level::DEBUG, foo_field) { |
865 | /// // some expensive work... |
866 | /// } |
867 | /// ``` |
868 | /// |
869 | /// [`enabled!`]: crate::enabled |
870 | /// [`span_enabled!`]: crate::span_enabled |
871 | #[macro_export ] |
872 | macro_rules! span_enabled { |
873 | ($($rest:tt)*)=> ( |
874 | $crate::enabled!(kind: $crate::metadata::Kind::SPAN, $($rest)*) |
875 | ) |
876 | } |
877 | |
878 | /// Checks whether a span or event is [enabled] based on the provided [metadata]. |
879 | /// |
880 | /// [enabled]: crate::Subscriber::enabled |
881 | /// [metadata]: crate::Metadata |
882 | /// |
883 | /// This macro is a specialized tool: it is intended to be used prior |
884 | /// to an expensive computation required *just* for that event, but |
885 | /// *cannot* be done as part of an argument to that event, such as |
886 | /// when multiple events are emitted (e.g., iterating over a collection |
887 | /// and emitting an event for each item). |
888 | /// |
889 | /// # Usage |
890 | /// |
891 | /// [Subscribers] can make filtering decisions based all the data included in a |
892 | /// span or event's [`Metadata`]. This means that it is possible for `enabled!` |
893 | /// to return a _false positive_ (indicating that something would be enabled |
894 | /// when it actually would not be) or a _false negative_ (indicating that |
895 | /// something would be disabled when it would actually be enabled). |
896 | /// |
897 | /// [Subscribers]: crate::subscriber::Subscriber |
898 | /// [`Metadata`]: crate::metadata::Metadata |
899 | /// |
900 | /// This occurs when a subscriber is using a _more specific_ filter than the |
901 | /// metadata provided to the `enabled!` macro. Some situations that can result |
902 | /// in false positives or false negatives include: |
903 | /// |
904 | /// - If a subscriber is using a filter which may enable a span or event based |
905 | /// on field names, but `enabled!` is invoked without listing field names, |
906 | /// `enabled!` may return a false negative if a specific field name would |
907 | /// cause the subscriber to enable something that would otherwise be disabled. |
908 | /// - If a subscriber is using a filter which enables or disables specific events by |
909 | /// file path and line number, a particular event may be enabled/disabled |
910 | /// even if an `enabled!` invocation with the same level, target, and fields |
911 | /// indicated otherwise. |
912 | /// - The subscriber can choose to enable _only_ spans or _only_ events, which `enabled` |
913 | /// will not reflect. |
914 | /// |
915 | /// `enabled!()` requires a [level](crate::Level) argument, an optional `target:` |
916 | /// argument, and an optional set of field names. If the fields are not provided, |
917 | /// they are considered to be unknown. `enabled!` attempts to match the |
918 | /// syntax of `event!()` as closely as possible, which can be seen in the |
919 | /// examples below. |
920 | /// |
921 | /// # Examples |
922 | /// |
923 | /// If the current subscriber is interested in recording `DEBUG`-level spans and |
924 | /// events in the current file and module path, this will evaluate to true: |
925 | /// ```rust |
926 | /// use tracing::{enabled, Level}; |
927 | /// |
928 | /// if enabled!(Level::DEBUG) { |
929 | /// // some expensive work... |
930 | /// } |
931 | /// ``` |
932 | /// |
933 | /// If the current subscriber is interested in recording spans and events |
934 | /// in the current file and module path, with the target "my_crate", and at the |
935 | /// level `DEBUG`, this will evaluate to true: |
936 | /// ```rust |
937 | /// # use tracing::{enabled, Level}; |
938 | /// if enabled!(target: "my_crate" , Level::DEBUG) { |
939 | /// // some expensive work... |
940 | /// } |
941 | /// ``` |
942 | /// |
943 | /// If the current subscriber is interested in recording spans and events |
944 | /// in the current file and module path, with the target "my_crate", at |
945 | /// the level `DEBUG`, and with a field named "hello", this will evaluate |
946 | /// to true: |
947 | /// |
948 | /// ```rust |
949 | /// # use tracing::{enabled, Level}; |
950 | /// if enabled!(target: "my_crate" , Level::DEBUG, hello) { |
951 | /// // some expensive work... |
952 | /// } |
953 | /// ``` |
954 | /// |
955 | /// # Alternatives |
956 | /// |
957 | /// `enabled!` queries subscribers with [`Metadata`] where |
958 | /// [`is_event`] and [`is_span`] both return `false`. Alternatively, |
959 | /// use [`event_enabled!`] or [`span_enabled!`] to ensure one of these |
960 | /// returns true. |
961 | /// |
962 | /// |
963 | /// [`Metadata`]: crate::Metadata |
964 | /// [`is_event`]: crate::Metadata::is_event |
965 | /// [`is_span`]: crate::Metadata::is_span |
966 | /// [`enabled!`]: crate::enabled |
967 | /// [`span_enabled!`]: crate::span_enabled |
968 | #[macro_export ] |
969 | macro_rules! enabled { |
970 | (kind: $kind:expr, target: $target:expr, $lvl:expr, { $($fields:tt)* } )=> ({ |
971 | if $crate::level_enabled!($lvl) { |
972 | use $crate::__macro_support::Callsite as _; |
973 | static CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite2! { |
974 | name: $crate::__macro_support::concat!( |
975 | "enabled " , |
976 | file!(), |
977 | ":" , |
978 | line!() |
979 | ), |
980 | kind: $kind.hint(), |
981 | target: $target, |
982 | level: $lvl, |
983 | fields: $($fields)* |
984 | }; |
985 | let interest = CALLSITE.interest(); |
986 | if !interest.is_never() && $crate::__macro_support::__is_enabled(CALLSITE.metadata(), interest) { |
987 | let meta = CALLSITE.metadata(); |
988 | $crate::dispatcher::get_default(|current| current.enabled(meta)) |
989 | } else { |
990 | false |
991 | } |
992 | } else { |
993 | false |
994 | } |
995 | }); |
996 | // Just target and level |
997 | (kind: $kind:expr, target: $target:expr, $lvl:expr ) => ( |
998 | $crate::enabled!(kind: $kind, target: $target, $lvl, { }) |
999 | ); |
1000 | (target: $target:expr, $lvl:expr ) => ( |
1001 | $crate::enabled!(kind: $crate::metadata::Kind::HINT, target: $target, $lvl, { }) |
1002 | ); |
1003 | |
1004 | // These four cases handle fields with no values |
1005 | (kind: $kind:expr, target: $target:expr, $lvl:expr, $($field:tt)*) => ( |
1006 | $crate::enabled!( |
1007 | kind: $kind, |
1008 | target: $target, |
1009 | $lvl, |
1010 | { $($field)*} |
1011 | ) |
1012 | ); |
1013 | (target: $target:expr, $lvl:expr, $($field:tt)*) => ( |
1014 | $crate::enabled!( |
1015 | kind: $crate::metadata::Kind::HINT, |
1016 | target: $target, |
1017 | $lvl, |
1018 | { $($field)*} |
1019 | ) |
1020 | ); |
1021 | |
1022 | // Level and field case |
1023 | (kind: $kind:expr, $lvl:expr, $($field:tt)*) => ( |
1024 | $crate::enabled!( |
1025 | kind: $kind, |
1026 | target: module_path!(), |
1027 | $lvl, |
1028 | { $($field)*} |
1029 | ) |
1030 | ); |
1031 | |
1032 | // Simplest `enabled!` case |
1033 | (kind: $kind:expr, $lvl:expr) => ( |
1034 | $crate::enabled!(kind: $kind, target: module_path!(), $lvl, { }) |
1035 | ); |
1036 | ($lvl:expr) => ( |
1037 | $crate::enabled!(kind: $crate::metadata::Kind::HINT, target: module_path!(), $lvl, { }) |
1038 | ); |
1039 | |
1040 | // Fallthrough from above |
1041 | ($lvl:expr, $($field:tt)*) => ( |
1042 | $crate::enabled!( |
1043 | kind: $crate::metadata::Kind::HINT, |
1044 | target: module_path!(), |
1045 | $lvl, |
1046 | { $($field)*} |
1047 | ) |
1048 | ); |
1049 | } |
1050 | |
1051 | /// Constructs an event at the trace level. |
1052 | /// |
1053 | /// This functions similarly to the [`event!`] macro. See [the top-level |
1054 | /// documentation][lib] for details on the syntax accepted by |
1055 | /// this macro. |
1056 | /// |
1057 | /// [`event!`]: crate::event! |
1058 | /// [lib]: crate#using-the-macros |
1059 | /// |
1060 | /// # Examples |
1061 | /// |
1062 | /// ```rust |
1063 | /// use tracing::trace; |
1064 | /// # #[derive(Debug, Copy, Clone)] struct Position { x: f32, y: f32 } |
1065 | /// # impl Position { |
1066 | /// # const ORIGIN: Self = Self { x: 0.0, y: 0.0 }; |
1067 | /// # fn dist(&self, other: Position) -> f32 { |
1068 | /// # let x = (other.x - self.x).exp2(); let y = (self.y - other.y).exp2(); |
1069 | /// # (x + y).sqrt() |
1070 | /// # } |
1071 | /// # } |
1072 | /// # fn main() { |
1073 | /// let pos = Position { x: 3.234, y: -1.223 }; |
1074 | /// let origin_dist = pos.dist(Position::ORIGIN); |
1075 | /// |
1076 | /// trace!(position = ?pos, ?origin_dist); |
1077 | /// trace!( |
1078 | /// target: "app_events" , |
1079 | /// position = ?pos, |
1080 | /// "x is {} and y is {}" , |
1081 | /// if pos.x >= 0.0 { "positive" } else { "negative" }, |
1082 | /// if pos.y >= 0.0 { "positive" } else { "negative" } |
1083 | /// ); |
1084 | /// # } |
1085 | /// ``` |
1086 | #[macro_export ] |
1087 | macro_rules! trace { |
1088 | (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1089 | $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($field)* }, $($arg)*) |
1090 | ); |
1091 | (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1092 | $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) |
1093 | ); |
1094 | (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1095 | $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) |
1096 | ); |
1097 | (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1098 | $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, { $($k).+ $($field)+ }) |
1099 | ); |
1100 | (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
1101 | $crate::event!(target: $target, parent: $parent, $crate::Level::TRACE, {}, $($arg)+) |
1102 | ); |
1103 | (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( |
1104 | $crate::event!( |
1105 | target: module_path!(), |
1106 | parent: $parent, |
1107 | $crate::Level::TRACE, |
1108 | { $($field)+ }, |
1109 | $($arg)+ |
1110 | ) |
1111 | ); |
1112 | (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( |
1113 | $crate::event!( |
1114 | target: module_path!(), |
1115 | parent: $parent, |
1116 | $crate::Level::TRACE, |
1117 | { $($k).+ = $($field)*} |
1118 | ) |
1119 | ); |
1120 | (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( |
1121 | $crate::event!( |
1122 | target: module_path!(), |
1123 | parent: $parent, |
1124 | $crate::Level::TRACE, |
1125 | { ?$($k).+ = $($field)*} |
1126 | ) |
1127 | ); |
1128 | (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( |
1129 | $crate::event!( |
1130 | target: module_path!(), |
1131 | parent: $parent, |
1132 | $crate::Level::TRACE, |
1133 | { %$($k).+ = $($field)*} |
1134 | ) |
1135 | ); |
1136 | (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( |
1137 | $crate::event!( |
1138 | target: module_path!(), |
1139 | parent: $parent, |
1140 | $crate::Level::TRACE, |
1141 | { $($k).+, $($field)*} |
1142 | ) |
1143 | ); |
1144 | (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( |
1145 | $crate::event!( |
1146 | target: module_path!(), |
1147 | parent: $parent, |
1148 | $crate::Level::TRACE, |
1149 | { ?$($k).+, $($field)*} |
1150 | ) |
1151 | ); |
1152 | (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( |
1153 | $crate::event!( |
1154 | target: module_path!(), |
1155 | parent: $parent, |
1156 | $crate::Level::TRACE, |
1157 | { %$($k).+, $($field)*} |
1158 | ) |
1159 | ); |
1160 | (parent: $parent:expr, $($arg:tt)+) => ( |
1161 | $crate::event!( |
1162 | target: module_path!(), |
1163 | parent: $parent, |
1164 | $crate::Level::TRACE, |
1165 | {}, |
1166 | $($arg)+ |
1167 | ) |
1168 | ); |
1169 | (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1170 | $crate::event!(target: $target, $crate::Level::TRACE, { $($field)* }, $($arg)*) |
1171 | ); |
1172 | (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( |
1173 | $crate::event!(target: $target, $crate::Level::TRACE, { $($k).+ $($field)* }) |
1174 | ); |
1175 | (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( |
1176 | $crate::event!(target: $target, $crate::Level::TRACE, { ?$($k).+ $($field)* }) |
1177 | ); |
1178 | (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( |
1179 | $crate::event!(target: $target, $crate::Level::TRACE, { %$($k).+ $($field)* }) |
1180 | ); |
1181 | (target: $target:expr, $($arg:tt)+ ) => ( |
1182 | $crate::event!(target: $target, $crate::Level::TRACE, {}, $($arg)+) |
1183 | ); |
1184 | ({ $($field:tt)+ }, $($arg:tt)+ ) => ( |
1185 | $crate::event!( |
1186 | target: module_path!(), |
1187 | $crate::Level::TRACE, |
1188 | { $($field)+ }, |
1189 | $($arg)+ |
1190 | ) |
1191 | ); |
1192 | ($($k:ident).+ = $($field:tt)*) => ( |
1193 | $crate::event!( |
1194 | target: module_path!(), |
1195 | $crate::Level::TRACE, |
1196 | { $($k).+ = $($field)*} |
1197 | ) |
1198 | ); |
1199 | ($($k:ident).+, $($field:tt)*) => ( |
1200 | $crate::event!( |
1201 | target: module_path!(), |
1202 | $crate::Level::TRACE, |
1203 | { $($k).+, $($field)*} |
1204 | ) |
1205 | ); |
1206 | (?$($k:ident).+, $($field:tt)*) => ( |
1207 | $crate::event!( |
1208 | target: module_path!(), |
1209 | $crate::Level::TRACE, |
1210 | { ?$($k).+, $($field)*} |
1211 | ) |
1212 | ); |
1213 | (%$($k:ident).+, $($field:tt)*) => ( |
1214 | $crate::event!( |
1215 | target: module_path!(), |
1216 | $crate::Level::TRACE, |
1217 | { %$($k).+, $($field)*} |
1218 | ) |
1219 | ); |
1220 | (?$($k:ident).+) => ( |
1221 | $crate::event!( |
1222 | target: module_path!(), |
1223 | $crate::Level::TRACE, |
1224 | { ?$($k).+ } |
1225 | ) |
1226 | ); |
1227 | (%$($k:ident).+) => ( |
1228 | $crate::event!( |
1229 | target: module_path!(), |
1230 | $crate::Level::TRACE, |
1231 | { %$($k).+ } |
1232 | ) |
1233 | ); |
1234 | ($($k:ident).+) => ( |
1235 | $crate::event!( |
1236 | target: module_path!(), |
1237 | $crate::Level::TRACE, |
1238 | { $($k).+ } |
1239 | ) |
1240 | ); |
1241 | ($($arg:tt)+) => ( |
1242 | $crate::event!( |
1243 | target: module_path!(), |
1244 | $crate::Level::TRACE, |
1245 | {}, |
1246 | $($arg)+ |
1247 | ) |
1248 | ); |
1249 | } |
1250 | |
1251 | /// Constructs an event at the debug level. |
1252 | /// |
1253 | /// This functions similarly to the [`event!`] macro. See [the top-level |
1254 | /// documentation][lib] for details on the syntax accepted by |
1255 | /// this macro. |
1256 | /// |
1257 | /// [`event!`]: crate::event! |
1258 | /// [lib]: crate#using-the-macros |
1259 | /// |
1260 | /// # Examples |
1261 | /// |
1262 | /// ```rust |
1263 | /// use tracing::debug; |
1264 | /// # fn main() { |
1265 | /// # #[derive(Debug)] struct Position { x: f32, y: f32 } |
1266 | /// |
1267 | /// let pos = Position { x: 3.234, y: -1.223 }; |
1268 | /// |
1269 | /// debug!(?pos.x, ?pos.y); |
1270 | /// debug!(target: "app_events" , position = ?pos, "New position" ); |
1271 | /// # } |
1272 | /// ``` |
1273 | #[macro_export ] |
1274 | macro_rules! debug { |
1275 | (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1276 | $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($field)* }, $($arg)*) |
1277 | ); |
1278 | (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1279 | $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) |
1280 | ); |
1281 | (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1282 | $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) |
1283 | ); |
1284 | (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1285 | $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, { $($k).+ $($field)+ }) |
1286 | ); |
1287 | (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
1288 | $crate::event!(target: $target, parent: $parent, $crate::Level::DEBUG, {}, $($arg)+) |
1289 | ); |
1290 | (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( |
1291 | $crate::event!( |
1292 | target: module_path!(), |
1293 | parent: $parent, |
1294 | $crate::Level::DEBUG, |
1295 | { $($field)+ }, |
1296 | $($arg)+ |
1297 | ) |
1298 | ); |
1299 | (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( |
1300 | $crate::event!( |
1301 | target: module_path!(), |
1302 | parent: $parent, |
1303 | $crate::Level::DEBUG, |
1304 | { $($k).+ = $($field)*} |
1305 | ) |
1306 | ); |
1307 | (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( |
1308 | $crate::event!( |
1309 | target: module_path!(), |
1310 | parent: $parent, |
1311 | $crate::Level::DEBUG, |
1312 | { ?$($k).+ = $($field)*} |
1313 | ) |
1314 | ); |
1315 | (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( |
1316 | $crate::event!( |
1317 | target: module_path!(), |
1318 | parent: $parent, |
1319 | $crate::Level::DEBUG, |
1320 | { %$($k).+ = $($field)*} |
1321 | ) |
1322 | ); |
1323 | (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( |
1324 | $crate::event!( |
1325 | target: module_path!(), |
1326 | parent: $parent, |
1327 | $crate::Level::DEBUG, |
1328 | { $($k).+, $($field)*} |
1329 | ) |
1330 | ); |
1331 | (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( |
1332 | $crate::event!( |
1333 | target: module_path!(), |
1334 | parent: $parent, |
1335 | $crate::Level::DEBUG, |
1336 | { ?$($k).+, $($field)*} |
1337 | ) |
1338 | ); |
1339 | (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( |
1340 | $crate::event!( |
1341 | target: module_path!(), |
1342 | parent: $parent, |
1343 | $crate::Level::DEBUG, |
1344 | { %$($k).+, $($field)*} |
1345 | ) |
1346 | ); |
1347 | (parent: $parent:expr, $($arg:tt)+) => ( |
1348 | $crate::event!( |
1349 | target: module_path!(), |
1350 | parent: $parent, |
1351 | $crate::Level::DEBUG, |
1352 | {}, |
1353 | $($arg)+ |
1354 | ) |
1355 | ); |
1356 | (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1357 | $crate::event!(target: $target, $crate::Level::DEBUG, { $($field)* }, $($arg)*) |
1358 | ); |
1359 | (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( |
1360 | $crate::event!(target: $target, $crate::Level::DEBUG, { $($k).+ $($field)* }) |
1361 | ); |
1362 | (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( |
1363 | $crate::event!(target: $target, $crate::Level::DEBUG, { ?$($k).+ $($field)* }) |
1364 | ); |
1365 | (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( |
1366 | $crate::event!(target: $target, $crate::Level::DEBUG, { %$($k).+ $($field)* }) |
1367 | ); |
1368 | (target: $target:expr, $($arg:tt)+ ) => ( |
1369 | $crate::event!(target: $target, $crate::Level::DEBUG, {}, $($arg)+) |
1370 | ); |
1371 | ({ $($field:tt)+ }, $($arg:tt)+ ) => ( |
1372 | $crate::event!( |
1373 | target: module_path!(), |
1374 | $crate::Level::DEBUG, |
1375 | { $($field)+ }, |
1376 | $($arg)+ |
1377 | ) |
1378 | ); |
1379 | ($($k:ident).+ = $($field:tt)*) => ( |
1380 | $crate::event!( |
1381 | target: module_path!(), |
1382 | $crate::Level::DEBUG, |
1383 | { $($k).+ = $($field)*} |
1384 | ) |
1385 | ); |
1386 | (?$($k:ident).+ = $($field:tt)*) => ( |
1387 | $crate::event!( |
1388 | target: module_path!(), |
1389 | $crate::Level::DEBUG, |
1390 | { ?$($k).+ = $($field)*} |
1391 | ) |
1392 | ); |
1393 | (%$($k:ident).+ = $($field:tt)*) => ( |
1394 | $crate::event!( |
1395 | target: module_path!(), |
1396 | $crate::Level::DEBUG, |
1397 | { %$($k).+ = $($field)*} |
1398 | ) |
1399 | ); |
1400 | ($($k:ident).+, $($field:tt)*) => ( |
1401 | $crate::event!( |
1402 | target: module_path!(), |
1403 | $crate::Level::DEBUG, |
1404 | { $($k).+, $($field)*} |
1405 | ) |
1406 | ); |
1407 | (?$($k:ident).+, $($field:tt)*) => ( |
1408 | $crate::event!( |
1409 | target: module_path!(), |
1410 | $crate::Level::DEBUG, |
1411 | { ?$($k).+, $($field)*} |
1412 | ) |
1413 | ); |
1414 | (%$($k:ident).+, $($field:tt)*) => ( |
1415 | $crate::event!( |
1416 | target: module_path!(), |
1417 | $crate::Level::DEBUG, |
1418 | { %$($k).+, $($field)*} |
1419 | ) |
1420 | ); |
1421 | (?$($k:ident).+) => ( |
1422 | $crate::event!( |
1423 | target: module_path!(), |
1424 | $crate::Level::DEBUG, |
1425 | { ?$($k).+ } |
1426 | ) |
1427 | ); |
1428 | (%$($k:ident).+) => ( |
1429 | $crate::event!( |
1430 | target: module_path!(), |
1431 | $crate::Level::DEBUG, |
1432 | { %$($k).+ } |
1433 | ) |
1434 | ); |
1435 | ($($k:ident).+) => ( |
1436 | $crate::event!( |
1437 | target: module_path!(), |
1438 | $crate::Level::DEBUG, |
1439 | { $($k).+ } |
1440 | ) |
1441 | ); |
1442 | ($($arg:tt)+) => ( |
1443 | $crate::event!( |
1444 | target: module_path!(), |
1445 | $crate::Level::DEBUG, |
1446 | {}, |
1447 | $($arg)+ |
1448 | ) |
1449 | ); |
1450 | } |
1451 | |
1452 | /// Constructs an event at the info level. |
1453 | /// |
1454 | /// This functions similarly to the [`event!`] macro. See [the top-level |
1455 | /// documentation][lib] for details on the syntax accepted by |
1456 | /// this macro. |
1457 | /// |
1458 | /// [`event!`]: crate::event! |
1459 | /// [lib]: crate#using-the-macros |
1460 | /// |
1461 | /// # Examples |
1462 | /// |
1463 | /// ```rust |
1464 | /// use tracing::info; |
1465 | /// # // this is so the test will still work in no-std mode |
1466 | /// # #[derive(Debug)] |
1467 | /// # pub struct Ipv4Addr; |
1468 | /// # impl Ipv4Addr { fn new(o1: u8, o2: u8, o3: u8, o4: u8) -> Self { Self } } |
1469 | /// # fn main() { |
1470 | /// # struct Connection { port: u32, speed: f32 } |
1471 | /// use tracing::field; |
1472 | /// |
1473 | /// let addr = Ipv4Addr::new(127, 0, 0, 1); |
1474 | /// let conn = Connection { port: 40, speed: 3.20 }; |
1475 | /// |
1476 | /// info!(conn.port, "connected to {:?}" , addr); |
1477 | /// info!( |
1478 | /// target: "connection_events" , |
1479 | /// ip = ?addr, |
1480 | /// conn.port, |
1481 | /// ?conn.speed, |
1482 | /// ); |
1483 | /// # } |
1484 | /// ``` |
1485 | #[macro_export ] |
1486 | macro_rules! info { |
1487 | (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1488 | $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($field)* }, $($arg)*) |
1489 | ); |
1490 | (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1491 | $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) |
1492 | ); |
1493 | (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1494 | $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) |
1495 | ); |
1496 | (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1497 | $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, { $($k).+ $($field)+ }) |
1498 | ); |
1499 | (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
1500 | $crate::event!(target: $target, parent: $parent, $crate::Level::INFO, {}, $($arg)+) |
1501 | ); |
1502 | (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( |
1503 | $crate::event!( |
1504 | target: module_path!(), |
1505 | parent: $parent, |
1506 | $crate::Level::INFO, |
1507 | { $($field)+ }, |
1508 | $($arg)+ |
1509 | ) |
1510 | ); |
1511 | (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( |
1512 | $crate::event!( |
1513 | target: module_path!(), |
1514 | parent: $parent, |
1515 | $crate::Level::INFO, |
1516 | { $($k).+ = $($field)*} |
1517 | ) |
1518 | ); |
1519 | (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( |
1520 | $crate::event!( |
1521 | target: module_path!(), |
1522 | parent: $parent, |
1523 | $crate::Level::INFO, |
1524 | { ?$($k).+ = $($field)*} |
1525 | ) |
1526 | ); |
1527 | (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( |
1528 | $crate::event!( |
1529 | target: module_path!(), |
1530 | parent: $parent, |
1531 | $crate::Level::INFO, |
1532 | { %$($k).+ = $($field)*} |
1533 | ) |
1534 | ); |
1535 | (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( |
1536 | $crate::event!( |
1537 | target: module_path!(), |
1538 | parent: $parent, |
1539 | $crate::Level::INFO, |
1540 | { $($k).+, $($field)*} |
1541 | ) |
1542 | ); |
1543 | (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( |
1544 | $crate::event!( |
1545 | target: module_path!(), |
1546 | parent: $parent, |
1547 | $crate::Level::INFO, |
1548 | { ?$($k).+, $($field)*} |
1549 | ) |
1550 | ); |
1551 | (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( |
1552 | $crate::event!( |
1553 | target: module_path!(), |
1554 | parent: $parent, |
1555 | $crate::Level::INFO, |
1556 | { %$($k).+, $($field)*} |
1557 | ) |
1558 | ); |
1559 | (parent: $parent:expr, $($arg:tt)+) => ( |
1560 | $crate::event!( |
1561 | target: module_path!(), |
1562 | parent: $parent, |
1563 | $crate::Level::INFO, |
1564 | {}, |
1565 | $($arg)+ |
1566 | ) |
1567 | ); |
1568 | (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1569 | $crate::event!(target: $target, $crate::Level::INFO, { $($field)* }, $($arg)*) |
1570 | ); |
1571 | (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( |
1572 | $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)* }) |
1573 | ); |
1574 | (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( |
1575 | $crate::event!(target: $target, $crate::Level::INFO, { ?$($k).+ $($field)* }) |
1576 | ); |
1577 | (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( |
1578 | $crate::event!(target: $target, $crate::Level::INFO, { $($k).+ $($field)* }) |
1579 | ); |
1580 | (target: $target:expr, $($arg:tt)+ ) => ( |
1581 | $crate::event!(target: $target, $crate::Level::INFO, {}, $($arg)+) |
1582 | ); |
1583 | ({ $($field:tt)+ }, $($arg:tt)+ ) => ( |
1584 | $crate::event!( |
1585 | target: module_path!(), |
1586 | $crate::Level::INFO, |
1587 | { $($field)+ }, |
1588 | $($arg)+ |
1589 | ) |
1590 | ); |
1591 | ($($k:ident).+ = $($field:tt)*) => ( |
1592 | $crate::event!( |
1593 | target: module_path!(), |
1594 | $crate::Level::INFO, |
1595 | { $($k).+ = $($field)*} |
1596 | ) |
1597 | ); |
1598 | (?$($k:ident).+ = $($field:tt)*) => ( |
1599 | $crate::event!( |
1600 | target: module_path!(), |
1601 | $crate::Level::INFO, |
1602 | { ?$($k).+ = $($field)*} |
1603 | ) |
1604 | ); |
1605 | (%$($k:ident).+ = $($field:tt)*) => ( |
1606 | $crate::event!( |
1607 | target: module_path!(), |
1608 | $crate::Level::INFO, |
1609 | { %$($k).+ = $($field)*} |
1610 | ) |
1611 | ); |
1612 | ($($k:ident).+, $($field:tt)*) => ( |
1613 | $crate::event!( |
1614 | target: module_path!(), |
1615 | $crate::Level::INFO, |
1616 | { $($k).+, $($field)*} |
1617 | ) |
1618 | ); |
1619 | (?$($k:ident).+, $($field:tt)*) => ( |
1620 | $crate::event!( |
1621 | target: module_path!(), |
1622 | $crate::Level::INFO, |
1623 | { ?$($k).+, $($field)*} |
1624 | ) |
1625 | ); |
1626 | (%$($k:ident).+, $($field:tt)*) => ( |
1627 | $crate::event!( |
1628 | target: module_path!(), |
1629 | $crate::Level::INFO, |
1630 | { %$($k).+, $($field)*} |
1631 | ) |
1632 | ); |
1633 | (?$($k:ident).+) => ( |
1634 | $crate::event!( |
1635 | target: module_path!(), |
1636 | $crate::Level::INFO, |
1637 | { ?$($k).+ } |
1638 | ) |
1639 | ); |
1640 | (%$($k:ident).+) => ( |
1641 | $crate::event!( |
1642 | target: module_path!(), |
1643 | $crate::Level::INFO, |
1644 | { %$($k).+ } |
1645 | ) |
1646 | ); |
1647 | ($($k:ident).+) => ( |
1648 | $crate::event!( |
1649 | target: module_path!(), |
1650 | $crate::Level::INFO, |
1651 | { $($k).+ } |
1652 | ) |
1653 | ); |
1654 | ($($arg:tt)+) => ( |
1655 | $crate::event!( |
1656 | target: module_path!(), |
1657 | $crate::Level::INFO, |
1658 | {}, |
1659 | $($arg)+ |
1660 | ) |
1661 | ); |
1662 | } |
1663 | |
1664 | /// Constructs an event at the warn level. |
1665 | /// |
1666 | /// This functions similarly to the [`event!`] macro. See [the top-level |
1667 | /// documentation][lib] for details on the syntax accepted by |
1668 | /// this macro. |
1669 | /// |
1670 | /// [`event!`]: crate::event! |
1671 | /// [lib]: crate#using-the-macros |
1672 | /// |
1673 | /// # Examples |
1674 | /// |
1675 | /// ```rust |
1676 | /// use tracing::warn; |
1677 | /// # fn main() { |
1678 | /// |
1679 | /// let warn_description = "Invalid Input" ; |
1680 | /// let input = &[0x27, 0x45]; |
1681 | /// |
1682 | /// warn!(?input, warning = warn_description); |
1683 | /// warn!( |
1684 | /// target: "input_events" , |
1685 | /// warning = warn_description, |
1686 | /// "Received warning for input: {:?}" , input, |
1687 | /// ); |
1688 | /// # } |
1689 | /// ``` |
1690 | #[macro_export ] |
1691 | macro_rules! warn { |
1692 | (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1693 | $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($field)* }, $($arg)*) |
1694 | ); |
1695 | (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1696 | $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) |
1697 | ); |
1698 | (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1699 | $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) |
1700 | ); |
1701 | (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1702 | $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, { $($k).+ $($field)+ }) |
1703 | ); |
1704 | (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
1705 | $crate::event!(target: $target, parent: $parent, $crate::Level::WARN, {}, $($arg)+) |
1706 | ); |
1707 | (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( |
1708 | $crate::event!( |
1709 | target: module_path!(), |
1710 | parent: $parent, |
1711 | $crate::Level::WARN, |
1712 | { $($field)+ }, |
1713 | $($arg)+ |
1714 | ) |
1715 | ); |
1716 | (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( |
1717 | $crate::event!( |
1718 | target: module_path!(), |
1719 | parent: $parent, |
1720 | $crate::Level::WARN, |
1721 | { $($k).+ = $($field)*} |
1722 | ) |
1723 | ); |
1724 | (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( |
1725 | $crate::event!( |
1726 | target: module_path!(), |
1727 | parent: $parent, |
1728 | $crate::Level::WARN, |
1729 | { ?$($k).+ = $($field)*} |
1730 | ) |
1731 | ); |
1732 | (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( |
1733 | $crate::event!( |
1734 | target: module_path!(), |
1735 | parent: $parent, |
1736 | $crate::Level::WARN, |
1737 | { %$($k).+ = $($field)*} |
1738 | ) |
1739 | ); |
1740 | (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( |
1741 | $crate::event!( |
1742 | target: module_path!(), |
1743 | parent: $parent, |
1744 | $crate::Level::WARN, |
1745 | { $($k).+, $($field)*} |
1746 | ) |
1747 | ); |
1748 | (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( |
1749 | $crate::event!( |
1750 | target: module_path!(), |
1751 | parent: $parent, |
1752 | $crate::Level::WARN, |
1753 | { ?$($k).+, $($field)*} |
1754 | ) |
1755 | ); |
1756 | (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( |
1757 | $crate::event!( |
1758 | target: module_path!(), |
1759 | parent: $parent, |
1760 | $crate::Level::WARN, |
1761 | { %$($k).+, $($field)*} |
1762 | ) |
1763 | ); |
1764 | (parent: $parent:expr, $($arg:tt)+) => ( |
1765 | $crate::event!( |
1766 | target: module_path!(), |
1767 | parent: $parent, |
1768 | $crate::Level::WARN, |
1769 | {}, |
1770 | $($arg)+ |
1771 | ) |
1772 | ); |
1773 | (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1774 | $crate::event!(target: $target, $crate::Level::WARN, { $($field)* }, $($arg)*) |
1775 | ); |
1776 | (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( |
1777 | $crate::event!(target: $target, $crate::Level::WARN, { $($k).+ $($field)* }) |
1778 | ); |
1779 | (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( |
1780 | $crate::event!(target: $target, $crate::Level::WARN, { ?$($k).+ $($field)* }) |
1781 | ); |
1782 | (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( |
1783 | $crate::event!(target: $target, $crate::Level::WARN, { %$($k).+ $($field)* }) |
1784 | ); |
1785 | (target: $target:expr, $($arg:tt)+ ) => ( |
1786 | $crate::event!(target: $target, $crate::Level::WARN, {}, $($arg)+) |
1787 | ); |
1788 | ({ $($field:tt)+ }, $($arg:tt)+ ) => ( |
1789 | $crate::event!( |
1790 | target: module_path!(), |
1791 | $crate::Level::WARN, |
1792 | { $($field)+ }, |
1793 | $($arg)+ |
1794 | ) |
1795 | ); |
1796 | ($($k:ident).+ = $($field:tt)*) => ( |
1797 | $crate::event!( |
1798 | target: module_path!(), |
1799 | $crate::Level::WARN, |
1800 | { $($k).+ = $($field)*} |
1801 | ) |
1802 | ); |
1803 | (?$($k:ident).+ = $($field:tt)*) => ( |
1804 | $crate::event!( |
1805 | target: module_path!(), |
1806 | $crate::Level::WARN, |
1807 | { ?$($k).+ = $($field)*} |
1808 | ) |
1809 | ); |
1810 | (%$($k:ident).+ = $($field:tt)*) => ( |
1811 | $crate::event!( |
1812 | target: module_path!(), |
1813 | $crate::Level::WARN, |
1814 | { %$($k).+ = $($field)*} |
1815 | ) |
1816 | ); |
1817 | ($($k:ident).+, $($field:tt)*) => ( |
1818 | $crate::event!( |
1819 | target: module_path!(), |
1820 | $crate::Level::WARN, |
1821 | { $($k).+, $($field)*} |
1822 | ) |
1823 | ); |
1824 | (?$($k:ident).+, $($field:tt)*) => ( |
1825 | $crate::event!( |
1826 | target: module_path!(), |
1827 | $crate::Level::WARN, |
1828 | { ?$($k).+, $($field)*} |
1829 | ) |
1830 | ); |
1831 | (%$($k:ident).+, $($field:tt)*) => ( |
1832 | $crate::event!( |
1833 | target: module_path!(), |
1834 | $crate::Level::WARN, |
1835 | { %$($k).+, $($field)*} |
1836 | ) |
1837 | ); |
1838 | (?$($k:ident).+) => ( |
1839 | $crate::event!( |
1840 | target: module_path!(), |
1841 | $crate::Level::WARN, |
1842 | { ?$($k).+ } |
1843 | ) |
1844 | ); |
1845 | (%$($k:ident).+) => ( |
1846 | $crate::event!( |
1847 | target: module_path!(), |
1848 | $crate::Level::WARN, |
1849 | { %$($k).+ } |
1850 | ) |
1851 | ); |
1852 | ($($k:ident).+) => ( |
1853 | $crate::event!( |
1854 | target: module_path!(), |
1855 | $crate::Level::WARN, |
1856 | { $($k).+ } |
1857 | ) |
1858 | ); |
1859 | ($($arg:tt)+) => ( |
1860 | $crate::event!( |
1861 | target: module_path!(), |
1862 | $crate::Level::WARN, |
1863 | {}, |
1864 | $($arg)+ |
1865 | ) |
1866 | ); |
1867 | } |
1868 | |
1869 | /// Constructs an event at the error level. |
1870 | /// |
1871 | /// This functions similarly to the [`event!`] macro. See [the top-level |
1872 | /// documentation][lib] for details on the syntax accepted by |
1873 | /// this macro. |
1874 | /// |
1875 | /// [`event!`]: crate::event! |
1876 | /// [lib]: crate#using-the-macros |
1877 | /// |
1878 | /// # Examples |
1879 | /// |
1880 | /// ```rust |
1881 | /// use tracing::error; |
1882 | /// # fn main() { |
1883 | /// |
1884 | /// let (err_info, port) = ("No connection" , 22); |
1885 | /// |
1886 | /// error!(port, error = %err_info); |
1887 | /// error!(target: "app_events" , "App Error: {}" , err_info); |
1888 | /// error!({ info = err_info }, "error on port: {}" , port); |
1889 | /// # } |
1890 | /// ``` |
1891 | #[macro_export ] |
1892 | macro_rules! error { |
1893 | (target: $target:expr, parent: $parent:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1894 | $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($field)* }, $($arg)*) |
1895 | ); |
1896 | (target: $target:expr, parent: $parent:expr, $($k:ident).+ $($field:tt)+ ) => ( |
1897 | $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) |
1898 | ); |
1899 | (target: $target:expr, parent: $parent:expr, ?$($k:ident).+ $($field:tt)+ ) => ( |
1900 | $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) |
1901 | ); |
1902 | (target: $target:expr, parent: $parent:expr, %$($k:ident).+ $($field:tt)+ ) => ( |
1903 | $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, { $($k).+ $($field)+ }) |
1904 | ); |
1905 | (target: $target:expr, parent: $parent:expr, $($arg:tt)+ ) => ( |
1906 | $crate::event!(target: $target, parent: $parent, $crate::Level::ERROR, {}, $($arg)+) |
1907 | ); |
1908 | (parent: $parent:expr, { $($field:tt)+ }, $($arg:tt)+ ) => ( |
1909 | $crate::event!( |
1910 | target: module_path!(), |
1911 | parent: $parent, |
1912 | $crate::Level::ERROR, |
1913 | { $($field)+ }, |
1914 | $($arg)+ |
1915 | ) |
1916 | ); |
1917 | (parent: $parent:expr, $($k:ident).+ = $($field:tt)*) => ( |
1918 | $crate::event!( |
1919 | target: module_path!(), |
1920 | parent: $parent, |
1921 | $crate::Level::ERROR, |
1922 | { $($k).+ = $($field)*} |
1923 | ) |
1924 | ); |
1925 | (parent: $parent:expr, ?$($k:ident).+ = $($field:tt)*) => ( |
1926 | $crate::event!( |
1927 | target: module_path!(), |
1928 | parent: $parent, |
1929 | $crate::Level::ERROR, |
1930 | { ?$($k).+ = $($field)*} |
1931 | ) |
1932 | ); |
1933 | (parent: $parent:expr, %$($k:ident).+ = $($field:tt)*) => ( |
1934 | $crate::event!( |
1935 | target: module_path!(), |
1936 | parent: $parent, |
1937 | $crate::Level::ERROR, |
1938 | { %$($k).+ = $($field)*} |
1939 | ) |
1940 | ); |
1941 | (parent: $parent:expr, $($k:ident).+, $($field:tt)*) => ( |
1942 | $crate::event!( |
1943 | target: module_path!(), |
1944 | parent: $parent, |
1945 | $crate::Level::ERROR, |
1946 | { $($k).+, $($field)*} |
1947 | ) |
1948 | ); |
1949 | (parent: $parent:expr, ?$($k:ident).+, $($field:tt)*) => ( |
1950 | $crate::event!( |
1951 | target: module_path!(), |
1952 | parent: $parent, |
1953 | $crate::Level::ERROR, |
1954 | { ?$($k).+, $($field)*} |
1955 | ) |
1956 | ); |
1957 | (parent: $parent:expr, %$($k:ident).+, $($field:tt)*) => ( |
1958 | $crate::event!( |
1959 | target: module_path!(), |
1960 | parent: $parent, |
1961 | $crate::Level::ERROR, |
1962 | { %$($k).+, $($field)*} |
1963 | ) |
1964 | ); |
1965 | (parent: $parent:expr, $($arg:tt)+) => ( |
1966 | $crate::event!( |
1967 | target: module_path!(), |
1968 | parent: $parent, |
1969 | $crate::Level::ERROR, |
1970 | {}, |
1971 | $($arg)+ |
1972 | ) |
1973 | ); |
1974 | (target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => ( |
1975 | $crate::event!(target: $target, $crate::Level::ERROR, { $($field)* }, $($arg)*) |
1976 | ); |
1977 | (target: $target:expr, $($k:ident).+ $($field:tt)* ) => ( |
1978 | $crate::event!(target: $target, $crate::Level::ERROR, { $($k).+ $($field)* }) |
1979 | ); |
1980 | (target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => ( |
1981 | $crate::event!(target: $target, $crate::Level::ERROR, { ?$($k).+ $($field)* }) |
1982 | ); |
1983 | (target: $target:expr, %$($k:ident).+ $($field:tt)* ) => ( |
1984 | $crate::event!(target: $target, $crate::Level::ERROR, { %$($k).+ $($field)* }) |
1985 | ); |
1986 | (target: $target:expr, $($arg:tt)+ ) => ( |
1987 | $crate::event!(target: $target, $crate::Level::ERROR, {}, $($arg)+) |
1988 | ); |
1989 | ({ $($field:tt)+ }, $($arg:tt)+ ) => ( |
1990 | $crate::event!( |
1991 | target: module_path!(), |
1992 | $crate::Level::ERROR, |
1993 | { $($field)+ }, |
1994 | $($arg)+ |
1995 | ) |
1996 | ); |
1997 | ($($k:ident).+ = $($field:tt)*) => ( |
1998 | $crate::event!( |
1999 | target: module_path!(), |
2000 | $crate::Level::ERROR, |
2001 | { $($k).+ = $($field)*} |
2002 | ) |
2003 | ); |
2004 | (?$($k:ident).+ = $($field:tt)*) => ( |
2005 | $crate::event!( |
2006 | target: module_path!(), |
2007 | $crate::Level::ERROR, |
2008 | { ?$($k).+ = $($field)*} |
2009 | ) |
2010 | ); |
2011 | (%$($k:ident).+ = $($field:tt)*) => ( |
2012 | $crate::event!( |
2013 | target: module_path!(), |
2014 | $crate::Level::ERROR, |
2015 | { %$($k).+ = $($field)*} |
2016 | ) |
2017 | ); |
2018 | ($($k:ident).+, $($field:tt)*) => ( |
2019 | $crate::event!( |
2020 | target: module_path!(), |
2021 | $crate::Level::ERROR, |
2022 | { $($k).+, $($field)*} |
2023 | ) |
2024 | ); |
2025 | (?$($k:ident).+, $($field:tt)*) => ( |
2026 | $crate::event!( |
2027 | target: module_path!(), |
2028 | $crate::Level::ERROR, |
2029 | { ?$($k).+, $($field)*} |
2030 | ) |
2031 | ); |
2032 | (%$($k:ident).+, $($field:tt)*) => ( |
2033 | $crate::event!( |
2034 | target: module_path!(), |
2035 | $crate::Level::ERROR, |
2036 | { %$($k).+, $($field)*} |
2037 | ) |
2038 | ); |
2039 | (?$($k:ident).+) => ( |
2040 | $crate::event!( |
2041 | target: module_path!(), |
2042 | $crate::Level::ERROR, |
2043 | { ?$($k).+ } |
2044 | ) |
2045 | ); |
2046 | (%$($k:ident).+) => ( |
2047 | $crate::event!( |
2048 | target: module_path!(), |
2049 | $crate::Level::ERROR, |
2050 | { %$($k).+ } |
2051 | ) |
2052 | ); |
2053 | ($($k:ident).+) => ( |
2054 | $crate::event!( |
2055 | target: module_path!(), |
2056 | $crate::Level::ERROR, |
2057 | { $($k).+ } |
2058 | ) |
2059 | ); |
2060 | ($($arg:tt)+) => ( |
2061 | $crate::event!( |
2062 | target: module_path!(), |
2063 | $crate::Level::ERROR, |
2064 | {}, |
2065 | $($arg)+ |
2066 | ) |
2067 | ); |
2068 | } |
2069 | |
2070 | /// Constructs a new static callsite for a span or event. |
2071 | #[doc (hidden)] |
2072 | #[macro_export ] |
2073 | macro_rules! callsite { |
2074 | (name: $name:expr, kind: $kind:expr, fields: $($fields:tt)*) => {{ |
2075 | $crate::callsite! { |
2076 | name: $name, |
2077 | kind: $kind, |
2078 | target: module_path!(), |
2079 | level: $crate::Level::TRACE, |
2080 | fields: $($fields)* |
2081 | } |
2082 | }}; |
2083 | ( |
2084 | name: $name:expr, |
2085 | kind: $kind:expr, |
2086 | level: $lvl:expr, |
2087 | fields: $($fields:tt)* |
2088 | ) => {{ |
2089 | $crate::callsite! { |
2090 | name: $name, |
2091 | kind: $kind, |
2092 | target: module_path!(), |
2093 | level: $lvl, |
2094 | fields: $($fields)* |
2095 | } |
2096 | }}; |
2097 | ( |
2098 | name: $name:expr, |
2099 | kind: $kind:expr, |
2100 | target: $target:expr, |
2101 | level: $lvl:expr, |
2102 | fields: $($fields:tt)* |
2103 | ) => {{ |
2104 | static META: $crate::Metadata<'static> = { |
2105 | $crate::metadata! { |
2106 | name: $name, |
2107 | target: $target, |
2108 | level: $lvl, |
2109 | fields: $crate::fieldset!( $($fields)* ), |
2110 | callsite: &CALLSITE, |
2111 | kind: $kind, |
2112 | } |
2113 | }; |
2114 | static CALLSITE: $crate::callsite::DefaultCallsite = $crate::callsite::DefaultCallsite::new(&META); |
2115 | CALLSITE.register(); |
2116 | &CALLSITE |
2117 | }}; |
2118 | } |
2119 | |
2120 | /// Constructs a new static callsite for a span or event. |
2121 | #[doc (hidden)] |
2122 | #[macro_export ] |
2123 | macro_rules! callsite2 { |
2124 | (name: $name:expr, kind: $kind:expr, fields: $($fields:tt)*) => {{ |
2125 | $crate::callsite2! { |
2126 | name: $name, |
2127 | kind: $kind, |
2128 | target: module_path!(), |
2129 | level: $crate::Level::TRACE, |
2130 | fields: $($fields)* |
2131 | } |
2132 | }}; |
2133 | ( |
2134 | name: $name:expr, |
2135 | kind: $kind:expr, |
2136 | level: $lvl:expr, |
2137 | fields: $($fields:tt)* |
2138 | ) => {{ |
2139 | $crate::callsite2! { |
2140 | name: $name, |
2141 | kind: $kind, |
2142 | target: module_path!(), |
2143 | level: $lvl, |
2144 | fields: $($fields)* |
2145 | } |
2146 | }}; |
2147 | ( |
2148 | name: $name:expr, |
2149 | kind: $kind:expr, |
2150 | target: $target:expr, |
2151 | level: $lvl:expr, |
2152 | fields: $($fields:tt)* |
2153 | ) => {{ |
2154 | static META: $crate::Metadata<'static> = { |
2155 | $crate::metadata! { |
2156 | name: $name, |
2157 | target: $target, |
2158 | level: $lvl, |
2159 | fields: $crate::fieldset!( $($fields)* ), |
2160 | callsite: &CALLSITE, |
2161 | kind: $kind, |
2162 | } |
2163 | }; |
2164 | $crate::callsite::DefaultCallsite::new(&META) |
2165 | }}; |
2166 | } |
2167 | |
2168 | #[macro_export ] |
2169 | // TODO: determine if this ought to be public API?` |
2170 | #[doc (hidden)] |
2171 | macro_rules! level_enabled { |
2172 | ($lvl:expr) => { |
2173 | $lvl <= $crate::level_filters::STATIC_MAX_LEVEL |
2174 | && $lvl <= $crate::level_filters::LevelFilter::current() |
2175 | }; |
2176 | } |
2177 | |
2178 | #[doc (hidden)] |
2179 | #[macro_export ] |
2180 | macro_rules! valueset { |
2181 | |
2182 | // === base case === |
2183 | (@ { $(,)* $($val:expr),* $(,)* }, $next:expr $(,)*) => { |
2184 | &[ $($val),* ] |
2185 | }; |
2186 | |
2187 | // === recursive case (more tts) === |
2188 | |
2189 | // TODO(#1138): determine a new syntax for uninitialized span fields, and |
2190 | // re-enable this. |
2191 | // (@{ $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = _, $($rest:tt)*) => { |
2192 | // $crate::valueset!(@ { $($out),*, (&$next, None) }, $next, $($rest)*) |
2193 | // }; |
2194 | (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { |
2195 | $crate::valueset!( |
2196 | @ { $($out),*, (&$next, Some(&debug(&$val) as &dyn Value)) }, |
2197 | $next, |
2198 | $($rest)* |
2199 | ) |
2200 | }; |
2201 | (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr, $($rest:tt)*) => { |
2202 | $crate::valueset!( |
2203 | @ { $($out),*, (&$next, Some(&display(&$val) as &dyn Value)) }, |
2204 | $next, |
2205 | $($rest)* |
2206 | ) |
2207 | }; |
2208 | (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr, $($rest:tt)*) => { |
2209 | $crate::valueset!( |
2210 | @ { $($out),*, (&$next, Some(&$val as &dyn Value)) }, |
2211 | $next, |
2212 | $($rest)* |
2213 | ) |
2214 | }; |
2215 | (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+, $($rest:tt)*) => { |
2216 | $crate::valueset!( |
2217 | @ { $($out),*, (&$next, Some(&$($k).+ as &dyn Value)) }, |
2218 | $next, |
2219 | $($rest)* |
2220 | ) |
2221 | }; |
2222 | (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+, $($rest:tt)*) => { |
2223 | $crate::valueset!( |
2224 | @ { $($out),*, (&$next, Some(&debug(&$($k).+) as &dyn Value)) }, |
2225 | $next, |
2226 | $($rest)* |
2227 | ) |
2228 | }; |
2229 | (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+, $($rest:tt)*) => { |
2230 | $crate::valueset!( |
2231 | @ { $($out),*, (&$next, Some(&display(&$($k).+) as &dyn Value)) }, |
2232 | $next, |
2233 | $($rest)* |
2234 | ) |
2235 | }; |
2236 | (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = ?$val:expr) => { |
2237 | $crate::valueset!( |
2238 | @ { $($out),*, (&$next, Some(&debug(&$val) as &dyn Value)) }, |
2239 | $next, |
2240 | ) |
2241 | }; |
2242 | (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = %$val:expr) => { |
2243 | $crate::valueset!( |
2244 | @ { $($out),*, (&$next, Some(&display(&$val) as &dyn Value)) }, |
2245 | $next, |
2246 | ) |
2247 | }; |
2248 | (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+ = $val:expr) => { |
2249 | $crate::valueset!( |
2250 | @ { $($out),*, (&$next, Some(&$val as &dyn Value)) }, |
2251 | $next, |
2252 | ) |
2253 | }; |
2254 | (@ { $(,)* $($out:expr),* }, $next:expr, $($k:ident).+) => { |
2255 | $crate::valueset!( |
2256 | @ { $($out),*, (&$next, Some(&$($k).+ as &dyn Value)) }, |
2257 | $next, |
2258 | ) |
2259 | }; |
2260 | (@ { $(,)* $($out:expr),* }, $next:expr, ?$($k:ident).+) => { |
2261 | $crate::valueset!( |
2262 | @ { $($out),*, (&$next, Some(&debug(&$($k).+) as &dyn Value)) }, |
2263 | $next, |
2264 | ) |
2265 | }; |
2266 | (@ { $(,)* $($out:expr),* }, $next:expr, %$($k:ident).+) => { |
2267 | $crate::valueset!( |
2268 | @ { $($out),*, (&$next, Some(&display(&$($k).+) as &dyn Value)) }, |
2269 | $next, |
2270 | ) |
2271 | }; |
2272 | |
2273 | // Handle literal names |
2274 | (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = ?$val:expr, $($rest:tt)*) => { |
2275 | $crate::valueset!( |
2276 | @ { $($out),*, (&$next, Some(&debug(&$val) as &dyn Value)) }, |
2277 | $next, |
2278 | $($rest)* |
2279 | ) |
2280 | }; |
2281 | (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = %$val:expr, $($rest:tt)*) => { |
2282 | $crate::valueset!( |
2283 | @ { $($out),*, (&$next, Some(&display(&$val) as &dyn Value)) }, |
2284 | $next, |
2285 | $($rest)* |
2286 | ) |
2287 | }; |
2288 | (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = $val:expr, $($rest:tt)*) => { |
2289 | $crate::valueset!( |
2290 | @ { $($out),*, (&$next, Some(&$val as &dyn Value)) }, |
2291 | $next, |
2292 | $($rest)* |
2293 | ) |
2294 | }; |
2295 | (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = ?$val:expr) => { |
2296 | $crate::valueset!( |
2297 | @ { $($out),*, (&$next, Some(&debug(&$val) as &dyn Value)) }, |
2298 | $next, |
2299 | ) |
2300 | }; |
2301 | (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = %$val:expr) => { |
2302 | $crate::valueset!( |
2303 | @ { $($out),*, (&$next, Some(&display(&$val) as &dyn Value)) }, |
2304 | $next, |
2305 | ) |
2306 | }; |
2307 | (@ { $(,)* $($out:expr),* }, $next:expr, $k:literal = $val:expr) => { |
2308 | $crate::valueset!( |
2309 | @ { $($out),*, (&$next, Some(&$val as &dyn Value)) }, |
2310 | $next, |
2311 | ) |
2312 | }; |
2313 | |
2314 | // Remainder is unparseable, but exists --- must be format args! |
2315 | (@ { $(,)* $($out:expr),* }, $next:expr, $($rest:tt)+) => { |
2316 | $crate::valueset!(@ { (&$next, Some(&format_args!($($rest)+) as &dyn Value)), $($out),* }, $next, ) |
2317 | }; |
2318 | |
2319 | // === entry === |
2320 | ($fields:expr, $($kvs:tt)+) => { |
2321 | { |
2322 | #[allow(unused_imports)] |
2323 | use $crate::field::{debug, display, Value}; |
2324 | let mut iter = $fields.iter(); |
2325 | $fields.value_set($crate::valueset!( |
2326 | @ { }, |
2327 | iter.next().expect("FieldSet corrupted (this is a bug)" ), |
2328 | $($kvs)+ |
2329 | )) |
2330 | } |
2331 | }; |
2332 | ($fields:expr,) => { |
2333 | { |
2334 | $fields.value_set(&[]) |
2335 | } |
2336 | }; |
2337 | } |
2338 | |
2339 | #[doc (hidden)] |
2340 | #[macro_export ] |
2341 | macro_rules! fieldset { |
2342 | // == base case == |
2343 | (@ { $(,)* $($out:expr),* $(,)* } $(,)*) => { |
2344 | &[ $($out),* ] |
2345 | }; |
2346 | |
2347 | // == recursive cases (more tts) == |
2348 | (@ { $(,)* $($out:expr),* } $($k:ident).+ = ?$val:expr, $($rest:tt)*) => { |
2349 | $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) |
2350 | }; |
2351 | (@ { $(,)* $($out:expr),* } $($k:ident).+ = %$val:expr, $($rest:tt)*) => { |
2352 | $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) |
2353 | }; |
2354 | (@ { $(,)* $($out:expr),* } $($k:ident).+ = $val:expr, $($rest:tt)*) => { |
2355 | $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) |
2356 | }; |
2357 | // TODO(#1138): determine a new syntax for uninitialized span fields, and |
2358 | // re-enable this. |
2359 | // (@ { $($out:expr),* } $($k:ident).+ = _, $($rest:tt)*) => { |
2360 | // $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) |
2361 | // }; |
2362 | (@ { $(,)* $($out:expr),* } ?$($k:ident).+, $($rest:tt)*) => { |
2363 | $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) |
2364 | }; |
2365 | (@ { $(,)* $($out:expr),* } %$($k:ident).+, $($rest:tt)*) => { |
2366 | $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) |
2367 | }; |
2368 | (@ { $(,)* $($out:expr),* } $($k:ident).+, $($rest:tt)*) => { |
2369 | $crate::fieldset!(@ { $($out),*, $crate::__tracing_stringify!($($k).+) } $($rest)*) |
2370 | }; |
2371 | |
2372 | // Handle literal names |
2373 | (@ { $(,)* $($out:expr),* } $k:literal = ?$val:expr, $($rest:tt)*) => { |
2374 | $crate::fieldset!(@ { $($out),*, $k } $($rest)*) |
2375 | }; |
2376 | (@ { $(,)* $($out:expr),* } $k:literal = %$val:expr, $($rest:tt)*) => { |
2377 | $crate::fieldset!(@ { $($out),*, $k } $($rest)*) |
2378 | }; |
2379 | (@ { $(,)* $($out:expr),* } $k:literal = $val:expr, $($rest:tt)*) => { |
2380 | $crate::fieldset!(@ { $($out),*, $k } $($rest)*) |
2381 | }; |
2382 | |
2383 | // Remainder is unparseable, but exists --- must be format args! |
2384 | (@ { $(,)* $($out:expr),* } $($rest:tt)+) => { |
2385 | $crate::fieldset!(@ { "message" , $($out),*, }) |
2386 | }; |
2387 | |
2388 | // == entry == |
2389 | ($($args:tt)*) => { |
2390 | $crate::fieldset!(@ { } $($args)*,) |
2391 | }; |
2392 | |
2393 | } |
2394 | |
2395 | #[cfg (feature = "log" )] |
2396 | #[doc (hidden)] |
2397 | #[macro_export ] |
2398 | macro_rules! level_to_log { |
2399 | ($level:expr) => { |
2400 | match $level { |
2401 | $crate::Level::ERROR => $crate::log::Level::Error, |
2402 | $crate::Level::WARN => $crate::log::Level::Warn, |
2403 | $crate::Level::INFO => $crate::log::Level::Info, |
2404 | $crate::Level::DEBUG => $crate::log::Level::Debug, |
2405 | _ => $crate::log::Level::Trace, |
2406 | } |
2407 | }; |
2408 | } |
2409 | |
2410 | #[doc (hidden)] |
2411 | #[macro_export ] |
2412 | macro_rules! __tracing_stringify { |
2413 | ($s:expr) => { |
2414 | stringify!($s) |
2415 | }; |
2416 | } |
2417 | |
2418 | #[cfg (not(feature = "log" ))] |
2419 | #[doc (hidden)] |
2420 | #[macro_export ] |
2421 | macro_rules! __tracing_log { |
2422 | ($level:expr, $callsite:expr, $value_set:expr) => {}; |
2423 | } |
2424 | |
2425 | #[cfg (feature = "log" )] |
2426 | #[doc (hidden)] |
2427 | #[macro_export ] |
2428 | macro_rules! __tracing_log { |
2429 | ($level:expr, $callsite:expr, $value_set:expr) => { |
2430 | $crate::if_log_enabled! { $level, { |
2431 | use $crate::log; |
2432 | let level = $crate::level_to_log!($level); |
2433 | if level <= log::max_level() { |
2434 | let meta = $callsite.metadata(); |
2435 | let log_meta = log::Metadata::builder() |
2436 | .level(level) |
2437 | .target(meta.target()) |
2438 | .build(); |
2439 | let logger = log::logger(); |
2440 | if logger.enabled(&log_meta) { |
2441 | $crate::__macro_support::__tracing_log(meta, logger, log_meta, $value_set) |
2442 | } |
2443 | } |
2444 | }} |
2445 | }; |
2446 | } |
2447 | |
2448 | #[cfg (not(feature = "log" ))] |
2449 | #[doc (hidden)] |
2450 | #[macro_export ] |
2451 | macro_rules! if_log_enabled { |
2452 | ($lvl:expr, $e:expr;) => { |
2453 | $crate::if_log_enabled! { $lvl, $e } |
2454 | }; |
2455 | ($lvl:expr, $if_log:block) => { |
2456 | $crate::if_log_enabled! { $lvl, $if_log else {} } |
2457 | }; |
2458 | ($lvl:expr, $if_log:block else $else_block:block) => { |
2459 | $else_block |
2460 | }; |
2461 | } |
2462 | |
2463 | #[cfg (all(feature = "log" , not(feature = "log-always" )))] |
2464 | #[doc (hidden)] |
2465 | #[macro_export ] |
2466 | macro_rules! if_log_enabled { |
2467 | ($lvl:expr, $e:expr;) => { |
2468 | $crate::if_log_enabled! { $lvl, $e } |
2469 | }; |
2470 | ($lvl:expr, $if_log:block) => { |
2471 | $crate::if_log_enabled! { $lvl, $if_log else {} } |
2472 | }; |
2473 | ($lvl:expr, $if_log:block else $else_block:block) => { |
2474 | if $crate::level_to_log!($lvl) <= $crate::log::STATIC_MAX_LEVEL { |
2475 | if !$crate::dispatcher::has_been_set() { |
2476 | $if_log |
2477 | } else { |
2478 | $else_block |
2479 | } |
2480 | } else { |
2481 | $else_block |
2482 | } |
2483 | }; |
2484 | } |
2485 | |
2486 | #[cfg (all(feature = "log" , feature = "log-always" ))] |
2487 | #[doc (hidden)] |
2488 | #[macro_export ] |
2489 | macro_rules! if_log_enabled { |
2490 | ($lvl:expr, $e:expr;) => { |
2491 | $crate::if_log_enabled! { $lvl, $e } |
2492 | }; |
2493 | ($lvl:expr, $if_log:block) => { |
2494 | $crate::if_log_enabled! { $lvl, $if_log else {} } |
2495 | }; |
2496 | ($lvl:expr, $if_log:block else $else_block:block) => { |
2497 | if $crate::level_to_log!($lvl) <= $crate::log::STATIC_MAX_LEVEL { |
2498 | #[allow(unused_braces)] |
2499 | $if_log |
2500 | } else { |
2501 | $else_block |
2502 | } |
2503 | }; |
2504 | } |
2505 | |