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 committed Dec 8, 2022
1 parent e81c61a commit 624b1fd
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 @@ -324,10 +324,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 @@ -358,7 +359,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 624b1fd

Please sign in to comment.