Skip to content
Closed
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
8 changes: 1 addition & 7 deletions src/fmt/writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ pub enum Target {
/// Logs will be sent to standard error.
Stderr,
/// Logs will be sent to a custom pipe.
#[deprecated = "\
This functionality is [broken](https://github.com/env-logger-rs/env_logger/issues/208) \
and nobody is working on fixing it\
"]
Pipe(Box<dyn io::Write + Send + 'static>),
}

Expand All @@ -41,7 +37,6 @@ impl fmt::Debug for Target {
match self {
Self::Stdout => "stdout",
Self::Stderr => "stderr",
#[allow(deprecated)]
Self::Pipe(_) => "pipe",
}
)
Expand All @@ -65,7 +60,6 @@ impl From<Target> for WritableTarget {
match target {
Target::Stdout => Self::Stdout,
Target::Stderr => Self::Stderr,
#[allow(deprecated)]
Target::Pipe(pipe) => Self::Pipe(Box::new(Mutex::new(pipe))),
}
}
Expand Down Expand Up @@ -199,7 +193,7 @@ impl Builder {
let writer = match mem::take(&mut self.target) {
WritableTarget::Stderr => BufferWriter::stderr(self.is_test, color_choice),
WritableTarget::Stdout => BufferWriter::stdout(self.is_test, color_choice),
WritableTarget::Pipe(pipe) => BufferWriter::pipe(self.is_test, color_choice, pipe),
WritableTarget::Pipe(pipe) => BufferWriter::pipe(color_choice, pipe),
};

Writer {
Expand Down
23 changes: 9 additions & 14 deletions src/fmt/writer/termcolor/extern_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ impl Formatter {

pub(in crate::fmt::writer) struct BufferWriter {
inner: termcolor::BufferWriter,
test_target: Option<WritableTarget>,
uncolored_target: Option<WritableTarget>,
}

pub(in crate::fmt) struct Buffer {
inner: termcolor::Buffer,
has_test_target: bool,
has_uncolored_target: bool,
}

impl BufferWriter {
pub(in crate::fmt::writer) fn stderr(is_test: bool, write_style: WriteStyle) -> Self {
BufferWriter {
inner: termcolor::BufferWriter::stderr(write_style.into_color_choice()),
test_target: if is_test {
uncolored_target: if is_test {
Some(WritableTarget::Stderr)
} else {
None
Expand All @@ -94,7 +94,7 @@ impl BufferWriter {
pub(in crate::fmt::writer) fn stdout(is_test: bool, write_style: WriteStyle) -> Self {
BufferWriter {
inner: termcolor::BufferWriter::stdout(write_style.into_color_choice()),
test_target: if is_test {
uncolored_target: if is_test {
Some(WritableTarget::Stdout)
} else {
None
Expand All @@ -103,30 +103,25 @@ impl BufferWriter {
}

pub(in crate::fmt::writer) fn pipe(
is_test: bool,
write_style: WriteStyle,
pipe: Box<Mutex<dyn io::Write + Send + 'static>>,
) -> Self {
BufferWriter {
// The inner Buffer is never printed from, but it is still needed to handle coloring and other formating
inner: termcolor::BufferWriter::stderr(write_style.into_color_choice()),
test_target: if is_test {
Some(WritableTarget::Pipe(pipe))
} else {
None
},
uncolored_target: Some(WritableTarget::Pipe(pipe)),
}
}

pub(in crate::fmt::writer) fn buffer(&self) -> Buffer {
Buffer {
inner: self.inner.buffer(),
has_test_target: self.test_target.is_some(),
has_uncolored_target: self.uncolored_target.is_some(),
}
}

pub(in crate::fmt::writer) fn print(&self, buf: &Buffer) -> io::Result<()> {
if let Some(target) = &self.test_target {
if let Some(target) = &self.uncolored_target {
// This impl uses the `eprint` and `print` macros
// instead of `termcolor`'s buffer.
// This is so their output can be captured by `cargo test`
Expand Down Expand Up @@ -164,7 +159,7 @@ impl Buffer {

fn set_color(&mut self, spec: &ColorSpec) -> io::Result<()> {
// Ignore styles for test captured logs because they can't be printed
if !self.has_test_target {
if !self.has_uncolored_target {
self.inner.set_color(spec)
} else {
Ok(())
Expand All @@ -173,7 +168,7 @@ impl Buffer {

fn reset(&mut self) -> io::Result<()> {
// Ignore styles for test captured logs because they can't be printed
if !self.has_test_target {
if !self.has_uncolored_target {
self.inner.reset()
} else {
Ok(())
Expand Down