Duplicate logging to stdout (#8495)

* Duplicate logging to stdout

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

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Arkadiy Paronyan
2021-03-31 13:46:14 +03:00
committed by GitHub
parent 2ed268286e
commit d294e51214
2 changed files with 16 additions and 1 deletions
@@ -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>
@@ -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)
}
}
}
@@ -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);