Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion client/tracing/src/logging/event_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub struct EventFormat<T = SystemTime> {
pub display_thread_name: bool,
/// Enable ANSI terminal colors for formatted output.
pub enable_color: bool,
/// Duplicate INFO, WARN and ERROR messages to stdout.
pub dup_to_stdout: bool,
}

impl<T> EventFormat<T>
Expand Down Expand Up @@ -123,7 +125,19 @@ where
writer: &mut dyn fmt::Write,
event: &Event,
) -> fmt::Result {
self.format_event_custom(CustomFmtContext::FmtContext(ctx), writer, event)
if self.dup_to_stdout && (
event.metadata().level() == &Level::INFO ||
event.metadata().level() == &Level::WARN ||
event.metadata().level() == &Level::ERROR
) {
let mut out = String::new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in tracing they tried to avoid re-allocation using lazy_static. Probably for performance reasons... 🤔 but I can't find the code anymore

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Maybe it's not relevant here I don't know)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string will only be allocated in the specific use case and only for INFO|WAR|ERROR messages that are rare. So I wouldn't bother.

self.format_event_custom(CustomFmtContext::FmtContext(ctx), &mut out, event)?;
writer.write_str(&out)?;
print!("{}", out);
Ok(())
} else {
self.format_event_custom(CustomFmtContext::FmtContext(ctx), writer, event)
}
}
}

Expand Down
1 change: 1 addition & 0 deletions client/tracing/src/logging/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ where
display_level: !simple,
display_thread_name: !simple,
enable_color,
dup_to_stdout: !atty::is(atty::Stream::Stderr) && atty::is(atty::Stream::Stdout),
};
let builder = FmtSubscriber::builder().with_env_filter(env_filter);

Expand Down