Skip to content

Commit 08fbe3b

Browse files
committed
process: avoid fine-grained locking for logs
1 parent fa7cd69 commit 08fbe3b

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

src/cli/log.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ where
5959
let maybe_rustup_log_directives = process.var("RUSTUP_LOG");
6060
let process = process.clone();
6161
let logger = tracing_subscriber::fmt::layer()
62-
.with_writer(move || process.stderr())
62+
.with_writer(process.stderr())
6363
.with_ansi(has_ansi);
6464
if let Ok(directives) = maybe_rustup_log_directives {
6565
let (env_filter, handle) = reload::Layer::new(

src/process/terminal_source.rs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use console::Term;
2-
use indicatif::TermLike;
31
use std::{
42
io::{self, Write},
53
num::NonZero,
@@ -8,6 +6,9 @@ use std::{
86
#[cfg(feature = "test")]
97
use anstream::StripStream;
108
use anstream::{AutoStream, ColorChoice};
9+
use console::Term;
10+
use indicatif::TermLike;
11+
use tracing_subscriber::fmt::MakeWriter;
1112

1213
use super::Process;
1314
#[cfg(feature = "test")]
@@ -170,25 +171,11 @@ impl TermLike for ColorableTerminal {
170171
}
171172
}
172173

173-
impl io::Write for ColorableTerminal {
174-
fn write(&mut self, buf: &[u8]) -> std::result::Result<usize, io::Error> {
175-
self.lock().as_write().write(buf)
176-
}
177-
178-
fn write_vectored(&mut self, bufs: &[std::io::IoSlice<'_>]) -> std::io::Result<usize> {
179-
self.lock().as_write().write_vectored(bufs)
180-
}
181-
182-
fn flush(&mut self) -> std::result::Result<(), io::Error> {
183-
self.lock().as_write().flush()
184-
}
174+
impl<'a> MakeWriter<'a> for ColorableTerminal {
175+
type Writer = ColorableTerminalLocked;
185176

186-
fn write_all(&mut self, buf: &[u8]) -> std::io::Result<()> {
187-
self.lock().as_write().write_all(buf)
188-
}
189-
190-
fn write_fmt(&mut self, args: std::fmt::Arguments<'_>) -> std::io::Result<()> {
191-
self.lock().as_write().write_fmt(args)
177+
fn make_writer(&self) -> Self::Writer {
178+
self.lock()
192179
}
193180
}
194181

0 commit comments

Comments
 (0)