-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
196 additions
and
54 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use indicatif::MultiProgress; | ||
use std::io; | ||
use tracing_core::{Event, Subscriber}; | ||
use tracing_subscriber::{ | ||
fmt::{ | ||
format::{self, Format}, | ||
FmtContext, FormatEvent, FormatFields, MakeWriter, | ||
}, | ||
registry::LookupSpan, | ||
}; | ||
|
||
#[derive(Clone)] | ||
pub struct IndicatifWriter { | ||
progress_bars: MultiProgress, | ||
} | ||
|
||
impl IndicatifWriter { | ||
pub(crate) fn new(pb: MultiProgress) -> Self { | ||
Self { progress_bars: pb } | ||
} | ||
} | ||
|
||
impl io::Write for IndicatifWriter { | ||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { | ||
self.progress_bars.suspend(|| io::stderr().write(buf)) | ||
} | ||
|
||
fn flush(&mut self) -> io::Result<()> { | ||
self.progress_bars.suspend(|| io::stderr().flush()) | ||
} | ||
} | ||
|
||
impl<'a> MakeWriter<'a> for IndicatifWriter { | ||
type Writer = IndicatifWriter; | ||
|
||
fn make_writer(&'a self) -> Self::Writer { | ||
self.clone() | ||
} | ||
} | ||
|
||
pub struct TracingFormatter; | ||
|
||
impl<S, N> FormatEvent<S, N> for TracingFormatter | ||
where | ||
S: Subscriber + for<'a> LookupSpan<'a>, | ||
N: for<'a> FormatFields<'a> + 'static, | ||
{ | ||
fn format_event( | ||
&self, | ||
ctx: &FmtContext<'_, S, N>, | ||
mut writer: format::Writer<'_>, | ||
event: &Event<'_>, | ||
) -> std::fmt::Result { | ||
let metadata = event.metadata(); | ||
if *metadata.level() == tracing_core::metadata::Level::INFO | ||
&& metadata.target().starts_with("rattler_build") | ||
{ | ||
ctx.format_fields(writer.by_ref(), event)?; | ||
writeln!(writer) | ||
} else { | ||
let default_format = Format::default(); | ||
default_format.format_event(ctx, writer, event) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.