-
Notifications
You must be signed in to change notification settings - Fork 825
tracing: fix macros "use of moved value" with log #1823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
874a462
bc81ef5
0ad95a9
68b56d0
c20567a
50fd7f2
b4c6208
ce02eda
a691c5b
a4e8d26
0c1ab2b
794040e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -980,7 +980,8 @@ pub mod __macro_support { | |||||||||||||||||||||||||||||||||||
use crate::{collect::Interest, Metadata}; | ||||||||||||||||||||||||||||||||||||
use core::fmt; | ||||||||||||||||||||||||||||||||||||
use core::sync::atomic::{AtomicUsize, Ordering}; | ||||||||||||||||||||||||||||||||||||
use tracing_core::Once; | ||||||||||||||||||||||||||||||||||||
use tracing_core::field::{ValueSet, Visit}; | ||||||||||||||||||||||||||||||||||||
use tracing_core::{Field, Once}; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
/// Callsite implementation used by macro-generated code. | ||||||||||||||||||||||||||||||||||||
/// | ||||||||||||||||||||||||||||||||||||
|
@@ -1109,6 +1110,53 @@ pub mod __macro_support { | |||||||||||||||||||||||||||||||||||
.finish() | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
/// Utility to format [`ValueSet`] for logging, used by macro-generated code. | ||||||||||||||||||||||||||||||||||||
/// | ||||||||||||||||||||||||||||||||||||
/// /!\ WARNING: This is *not* a stable API! /!\ | ||||||||||||||||||||||||||||||||||||
/// This type, and all code contained in the `__macro_support` module, is | ||||||||||||||||||||||||||||||||||||
/// a *private* API of `tracing`. It is exposed publicly because it is used | ||||||||||||||||||||||||||||||||||||
/// by the `tracing` macros, but it is not part of the stable versioned API. | ||||||||||||||||||||||||||||||||||||
/// Breaking changes to this module may occur in small-numbered versions | ||||||||||||||||||||||||||||||||||||
/// without warning. | ||||||||||||||||||||||||||||||||||||
#[derive(Debug)] | ||||||||||||||||||||||||||||||||||||
pub struct LogValueSet<'a>(pub &'a ValueSet<'a>); | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i have a slight preference for giving this a
Skepfyr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
impl<'a> fmt::Display for LogValueSet<'a> { | ||||||||||||||||||||||||||||||||||||
Skepfyr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||||||||||||||||||||||||||||||||||
let mut visit = LogVisitor { | ||||||||||||||||||||||||||||||||||||
f, | ||||||||||||||||||||||||||||||||||||
is_first: true, | ||||||||||||||||||||||||||||||||||||
result: Ok(()), | ||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||
self.0.record(&mut visit); | ||||||||||||||||||||||||||||||||||||
visit.result | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
struct LogVisitor<'a, 'b> { | ||||||||||||||||||||||||||||||||||||
Skepfyr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||
f: &'a mut fmt::Formatter<'b>, | ||||||||||||||||||||||||||||||||||||
is_first: bool, | ||||||||||||||||||||||||||||||||||||
result: fmt::Result, | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
impl Visit for LogVisitor<'_, '_> { | ||||||||||||||||||||||||||||||||||||
Skepfyr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||
fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) { | ||||||||||||||||||||||||||||||||||||
let res = if self.is_first { | ||||||||||||||||||||||||||||||||||||
self.is_first = false; | ||||||||||||||||||||||||||||||||||||
if field.name() == "message" { | ||||||||||||||||||||||||||||||||||||
write!(self.f, "{:?}", value) | ||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||
write!(self.f, "{}={:?}", field.name(), value) | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||
write!(self.f, " {}={:?}", field.name(), value) | ||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||
Comment on lines
+1154
to
+1163
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, take it or leave it: this might look slightly nicer as a
Suggested change
though, up to you There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer the explicit something is only weird about the first one of the if. However, your snippet does produce a different output to mine, in the case of message not being the first field. Mine would produce:
whereas yours would produce:
Is that behaviour ok, or should I change it to be in line with yours? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in practice, the |
||||||||||||||||||||||||||||||||||||
if let Err(err) = res { | ||||||||||||||||||||||||||||||||||||
self.result = self.result.and(Err(err)); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
mod sealed { | ||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -32,22 +32,24 @@ macro_rules! span { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
fields: $($fields)* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let mut interest = $crate::collect::Interest::never(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(|value_set| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if $crate::level_enabled!($lvl) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&& { interest = CALLSITE.interest(); !interest.is_never() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&& CALLSITE.is_enabled(interest) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let meta = CALLSITE.metadata(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// span with explicit parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::Span::child_of($parent, meta, &value_set) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let span = CALLSITE.disabled_span(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::if_log_enabled! { $lvl, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
span.record_all(&value_set); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
span | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
})($crate::valueset!(CALLSITE.metadata().fields(), $($fields)*)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if $crate::level_enabled!($lvl) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&& { interest = CALLSITE.interest(); !interest.is_never() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&& CALLSITE.is_enabled(interest) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let meta = CALLSITE.metadata(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// span with explicit parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::Span::child_of( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$parent, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
meta, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&$crate::valueset!(meta.fields(), $($fields)*), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let span = CALLSITE.disabled_span(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::if_log_enabled! { $lvl, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
span.record_all(&$crate::valueset!(CALLSITE.metadata().fields(), $($fields)*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
span | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -62,22 +64,23 @@ macro_rules! span { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let mut interest = $crate::collect::Interest::never(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(|value_set| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if $crate::level_enabled!($lvl) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&& { interest = CALLSITE.interest(); !interest.is_never() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&& CALLSITE.is_enabled(interest) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let meta = CALLSITE.metadata(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// span with contextual parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::Span::new(meta, &value_set) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let span = CALLSITE.disabled_span(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::if_log_enabled! { $lvl, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
span.record_all(&value_set); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
span | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
})($crate::valueset!(CALLSITE.metadata().fields(), $($fields)*)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if $crate::level_enabled!($lvl) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&& { interest = CALLSITE.interest(); !interest.is_never() } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&& CALLSITE.is_enabled(interest) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let meta = CALLSITE.metadata(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// span with contextual parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::Span::new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
meta, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&$crate::valueset!(meta.fields(), $($fields)*), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let span = CALLSITE.disabled_span(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::if_log_enabled! { $lvl, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
span.record_all(&$crate::valueset!(CALLSITE.metadata().fields(), $($fields)*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
span | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -594,25 +597,33 @@ macro_rules! event { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
level: $lvl, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fields: $($fields)* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(|value_set: $crate::field::ValueSet| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let enabled = $crate::level_enabled!($lvl) && { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let interest = CALLSITE.interest(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
!interest.is_never() && CALLSITE.is_enabled(interest) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if enabled { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(|value_set: $crate::field::ValueSet| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::__tracing_log!( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
target: $target, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$lvl, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&value_set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let meta = CALLSITE.metadata(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// event with explicit parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::Event::child_of( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$parent, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
meta, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&value_set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
})($crate::valueset!(CALLSITE.metadata().fields(), $($fields)*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a reason we still need the closure in the
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't work for the reasons mentioned elsewhere, however I can replace the closures with function calls which may be preferable (it also appears to improve perf, see benchmarking comment). However, those functions do look a bit weird: #[inline]
pub fn log_and_dispatcht(target: &str, callsite: &MacroCallsite, value_set: ValueSet) {
let meta = callsite.metadata();
// event with contextual parent
$crate::Event::dispatch(
meta,
&value_set
);
$crate::__tracing_log!(
target: target,
$lvl,
&value_set
);
} and similarly a |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::__tracing_log!( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
target: $target, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$lvl, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
value_set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&$crate::valueset!(CALLSITE.metadata().fields(), $($fields)*) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if $crate::level_enabled!($lvl) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let interest = CALLSITE.interest(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if !interest.is_never() && CALLSITE.is_enabled(interest) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let meta = CALLSITE.metadata(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// event with explicit parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::Event::child_of( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$parent, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
meta, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&value_set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
})($crate::valueset!(CALLSITE.metadata().fields(), $($fields)*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(target: $target:expr, parent: $parent:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -643,25 +654,31 @@ macro_rules! event { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
level: $lvl, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fields: $($fields)* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(|value_set: $crate::field::ValueSet| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let enabled = $crate::level_enabled!($lvl) && { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let interest = CALLSITE.interest(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
!interest.is_never() && CALLSITE.is_enabled(interest) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if enabled { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(|value_set: $crate::field::ValueSet| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let meta = CALLSITE.metadata(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// event with contextual parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::Event::dispatch( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
meta, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&value_set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::__tracing_log!( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
target: $target, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$lvl, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&value_set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
})($crate::valueset!(CALLSITE.metadata().fields(), $($fields)*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similarly, it seems like the closure should be able to be replaced by a |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::__tracing_log!( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
target: $target, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$lvl, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
value_set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&$crate::valueset!(CALLSITE.metadata().fields(), $($fields)*) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if $crate::level_enabled!($lvl) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let interest = CALLSITE.interest(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if !interest.is_never() && CALLSITE.is_enabled(interest) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let meta = CALLSITE.metadata(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//let value_set = $crate::valueset!(meta.fields(), $($fields)*); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// event with contextual parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::Event::dispatch( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
meta, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
&value_set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
})($crate::valueset!(CALLSITE.metadata().fields(), $($fields)*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(target: $target:expr, $lvl:expr, { $($fields:tt)* }, $($arg:tt)+ ) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::event!( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -2160,50 +2177,16 @@ macro_rules! __tracing_stringify { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
#[doc(hidden)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#[macro_export] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
macro_rules! __tracing_log { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(target: $target:expr, $level:expr, $($field:tt)+ ) => {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(target: $target:expr, $level:expr, $value_set:expr ) => {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#[cfg(feature = "log")] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#[doc(hidden)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#[macro_export] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
macro_rules! __tracing_log { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(target: $target:expr, $level:expr, $value_set:ident ) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(target: $target:expr, $level:expr, $value_set:expr ) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$crate::if_log_enabled! { $level, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use $crate::{log, field}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
struct LogValueSet<'a>(&'a field::ValueSet<'a>); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
impl<'a> std::fmt::Display for LogValueSet<'a> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let mut visit = Visit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
f, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
is_first: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
result: Ok(()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.0.record(&mut visit); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
visit.result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
struct Visit<'a, 'b> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
f: &'a mut std::fmt::Formatter<'b>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
is_first: bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
result: std::fmt::Result, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
impl field::Visit for Visit<'_, '_> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fn record_debug(&mut self, field: &field::Field, value: &dyn std::fmt::Debug) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let res = if self.is_first { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.is_first = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if field.name() == "message" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
write!(self.f, "{:?}", value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
write!(self.f, "{}={:?}", field.name(), value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
write!(self.f, " {}={:?}", field.name(), value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if let Err(err) = res { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.result = self.result.and(Err(err)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use $crate::log; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let level = $crate::level_to_log!($level); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if level <= log::max_level() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let log_meta = log::Metadata::builder() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -2217,7 +2200,7 @@ macro_rules! __tracing_log { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
.module_path(Some(module_path!())) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.line(Some(line!())) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.metadata(log_meta) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.args(format_args!("{}", LogValueSet(&$value_set))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.args(format_args!("{}", $crate::__macro_support::LogValueSet($value_set))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.build()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.