mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user