Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Duplicate logging to stdout (#8495)
Browse files Browse the repository at this point in the history
* Duplicate logging to stdout

* Update client/tracing/src/logging/event_format.rs

Co-authored-by: Bastian Köcher <[email protected]>

Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
arkpar and bkchr authored Mar 31, 2021
1 parent 3e96c69 commit 70f1b61
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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();
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

0 comments on commit 70f1b61

Please sign in to comment.