-
I'm porting code from slog to tracing. Here is the slog part: macro_rules! fatal {
($logger:expr, $msg:expr) => {{
let owned_kv = ($logger).list();
let s = crate::util::format_kv_list(&owned_kv);
if s.is_empty() {
panic!("{}", $msg)
} else {
panic!("{}, {}", $msg, s)
}
}};
($logger:expr, $fmt:expr, $($arg:tt)+) => {{
fatal!($logger, format_args!($fmt, $($arg)+))
}};
}
fatal!(logger, "cannot find correspond read state from pending map"); where I learned that pub(crate) fn current_span_fields() -> String {
let span = Span::current();
match span.metadata() {
None => "".to_owned(),
Some(metadata) => {
let fields = metadata.fields();
}
}
}
macro_rules! fatal {
($msg:expr) => {{
let s = crate::util::current_span_fields();
if s.is_empty() {
panic!("{}", $msg)
} else {
panic!("{}, {}", $msg, s)
}
}};
($fmt:expr, $($arg:tt)+) => {{
fatal!(format_args!($fmt, $($arg)+))
}};
} But it doesn't seems we have the counterpart to |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
You're not incorrect. The reason you've run into this limitation is that
With all that being said, I suspect that tracing-error or eyre with a custom spantrace formatter might get you close to what you're looking to accomplish. |
Beta Was this translation helpful? Give feedback.
-
@davidbarsky I found that it's actually the nested spans capture key values already. I write my own #[macro_export]
macro_rules! fatal {
($($arg:tt)*) => {{
let prev = std::panic::take_hook();
std::panic::set_hook(Box::new(move |info| {
tracing::error!("{info}");
prev(info);
}));
panic!($($arg)*);
}};
} |
Beta Was this translation helpful? Give feedback.
@davidbarsky I found that it's actually the nested spans capture key values already. I write my own
fatal
like: