tracing: Log field values that aren't valid UTF-8
This ensures that we retain as much logged information as possible, while still enabling us to identify field values that cause problems.
This commit is contained in:
parent
ba831f814a
commit
c87205e5e0
|
@ -490,23 +490,12 @@ pub extern "C" fn tracing_log(
|
||||||
let meta = callsite.metadata();
|
let meta = callsite.metadata();
|
||||||
assert!(meta.is_event());
|
assert!(meta.is_event());
|
||||||
|
|
||||||
if level_enabled!(*meta.level()) {
|
if level_enabled!(*meta.level()) && callsite.is_enabled() {
|
||||||
if callsite.is_enabled() {
|
|
||||||
/// Dispatch the event.
|
|
||||||
///
|
|
||||||
/// We wrap this in a function so that we can use `?` to collect and raise
|
|
||||||
/// UTF-8 errors without allocating. We use a function instead of a closure
|
|
||||||
/// so that we can force it to be inlined.
|
|
||||||
#[inline(always)]
|
|
||||||
fn dispatch_event(
|
|
||||||
meta: &'static Metadata,
|
|
||||||
field_values: &[*const c_char],
|
|
||||||
) -> Result<(), str::Utf8Error> {
|
|
||||||
let mut fi = meta.fields().iter();
|
let mut fi = meta.fields().iter();
|
||||||
let mut vi = field_values
|
let mut vi = field_values
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&p| unsafe { CStr::from_ptr(p) })
|
.map(|&p| unsafe { CStr::from_ptr(p) })
|
||||||
.map(|cs| cs.to_str());
|
.map(|cs| cs.to_string_lossy());
|
||||||
|
|
||||||
macro_rules! dispatch {
|
macro_rules! dispatch {
|
||||||
($n:tt) => {
|
($n:tt) => {
|
||||||
|
@ -516,7 +505,7 @@ pub extern "C" fn tracing_log(
|
||||||
$n,
|
$n,
|
||||||
(
|
(
|
||||||
&fi.next().unwrap(),
|
&fi.next().unwrap(),
|
||||||
Some(&vi.next().unwrap()? as &dyn Value)
|
Some(&vi.next().unwrap().as_ref() as &dyn Value)
|
||||||
)
|
)
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
|
@ -559,17 +548,5 @@ pub extern "C" fn tracing_log(
|
||||||
32 => dispatch!(32),
|
32 => dispatch!(32),
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Err(e) = dispatch_event(meta, field_values) {
|
|
||||||
tracing::error!(
|
|
||||||
"{}: Field value was not valid UTF-8: {}",
|
|
||||||
callsite.metadata().name(),
|
|
||||||
e
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue