You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I create tracing events with a boolean marker field like
# `e` is an `eyre` `Report`.
error!(has_emoji = true, some_other_field = "value", "{e:#}");
I then implement tracing_subscriber::fmt::FormatEvent for my custom event formatter, something like:
impl<S,N> tracing_subscriber::fmt::FormatEvent<S,N>forEmojiFmtwhereS: tracing::subscriber::Subscriber + for<'a> tracing_subscriber::registry::LookupSpan<'a>,N:for<'a> tracing_subscriber::fmt::FormatFields<'a> + 'static,{fnformat_event(&self,ctx:&tracing_subscriber::fmt::FmtContext<'_,S,N>,mutwriter: tracing_subscriber::fmt::format::Writer<'_>,event:&tracing::Event<'_>,) -> Result<(), std::fmt::Error>{// Detect whether the message already has an emoji, so we don't add another one.letmut visitor = HasEmojiVisitor{has_emoji:false};
event.record(&mut visitor);// Get the emoji for the log level, unless the message already has an emoji.let maybe_emoiji_message = {if visitor.has_emoji{"".to_owned()}else{let level_emoji = get_emoji_for_log_level(event.metadata().level());format!("{} ", level_emoji)}};write!(writer, "{}", maybe_emoiji_message).expect("Invalid message write in tracing's format_event");// TODO: Get rid of the has_emoji field at the end after the message somehowuse tracing_subscriber::fmt::FormatFields;
ctx.format_fields(writer.by_ref(), event)?;writeln!(writer)}}
The problem is that when I display the event with ctx.format_fields(writer.by_ref(), event)?; at the bottom, it also prints the has_emoji = true part, which i'd like to skip.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I create tracing events with a boolean marker field like
I then implement
tracing_subscriber::fmt::FormatEvent
for my custom event formatter, something like:The problem is that when I display the event with
ctx.format_fields(writer.by_ref(), event)?;
at the bottom, it also prints thehas_emoji = true
part, which i'd like to skip.I scoured the docs, and found https://docs.rs/tracing-subscriber/0.3.18/tracing_subscriber/field/index.html but none of the utilities there allows skipping a field.
How could I got about implementing this, while keeping the default formatting?
Is copying and adapting the whole of
https://docs.rs/tracing-subscriber/0.3.18/tracing_subscriber/fmt/format/struct.DefaultFields.html
and
https://docs.rs/tracing-subscriber/0.3.18/tracing_subscriber/fmt/format/struct.DefaultVisitor.html
the only way of doing this?
Or perhaps there's a different better way?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions