Skip to content

Commit

Permalink
Do not panic in the log statement when the tty closes.
Browse files Browse the repository at this point in the history
Fixes: #53
  • Loading branch information
Allen-Webb authored and cardoe committed Jan 31, 2024
1 parent d6a7e18 commit b5b515e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,11 @@ impl Log for StdErrLog {
Level::Trace => Color::Blue,
};
{
// A failure here indicates the stream closed. Do not panic.
writer
.get_mut()
.set_color(ColorSpec::new().set_fg(Some(color)))
.expect("failed to set color");
.ok();
}

if self.show_module_names {
Expand Down Expand Up @@ -359,7 +360,8 @@ impl Log for StdErrLog {
}
let _ = writeln!(writer, "{}", record.args());
{
writer.get_mut().reset().expect("failed to reset the color");
// A failure here indicates the stream closed. Do not panic.
writer.get_mut().reset().ok();
}
}

Expand Down

0 comments on commit b5b515e

Please sign in to comment.