Skip to content

Commit 92b7523

Browse files
committed
fixup! fixup! refactor(log): reimplement log using tracing
1 parent 0b3e73b commit 92b7523

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

src/bin/rustup-init.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ use rustup::cli::rustup_mode;
2727
#[cfg(windows)]
2828
use rustup::cli::self_update;
2929
use rustup::cli::setup_mode;
30-
use rustup::currentprocess::{
31-
filesource::StderrSource, process, varsource::VarSource, with_runtime, OSProcess,
32-
};
30+
use rustup::currentprocess::{process, varsource::VarSource, with_runtime, OSProcess};
3331
use rustup::env_var::RUST_RECURSION_COUNT_MAX;
3432
use rustup::is_proxyable_tools;
3533
use rustup::utils::utils::{self, ExitCode};
@@ -59,11 +57,7 @@ async fn maybe_trace_rustup() -> Result<utils::ExitCode> {
5957

6058
#[cfg(feature = "otel")]
6159
let telemetry = rustup::cli::log::telemetry()?;
62-
let console_logger = {
63-
let curr_process = process();
64-
let has_ansi = curr_process.stderr().is_a_tty();
65-
rustup::cli::log::console_logger(curr_process, has_ansi)
66-
};
60+
let console_logger = rustup::cli::log::console_logger(process());
6761
let subscriber = {
6862
#[cfg(feature = "otel")]
6963
{

src/cli/log.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tracing_subscriber::{
1212
};
1313

1414
use crate::{
15-
currentprocess::{filesource::StderrSource as _, varsource::VarSource as _, Process},
15+
currentprocess::{filesource::StderrSource, varsource::VarSource as _, Process},
1616
utils::notify::NotificationLevel,
1717
};
1818

@@ -42,14 +42,15 @@ macro_rules! err {
4242
/// When the `RUST_LOG` environment variable is present, a standard [`tracing_subscriber`]
4343
/// formatter will be used according to the filtering directives set in its value.
4444
/// Otherwise, this logger will use [`EventFormatter`] to mimic "classic" Rustup `stderr` output.
45-
pub fn console_logger<S>(process: Process, with_ansi: bool) -> impl Layer<S>
45+
pub fn console_logger<S>(process: Process) -> impl Layer<S>
4646
where
4747
S: Subscriber + for<'span> LookupSpan<'span>,
4848
{
4949
let maybe_rust_log_directives = process.var_os("RUST_LOG").clone();
50+
let has_ansi = process.stderr().is_a_tty();
5051
let logger = tracing_subscriber::fmt::layer()
5152
.with_writer(move || process.stderr())
52-
.with_ansi(with_ansi);
53+
.with_ansi(has_ansi);
5354
if let Some(directives) = maybe_rust_log_directives {
5455
let env_filter = EnvFilter::builder()
5556
.with_default_directive(LevelFilter::INFO.into())

src/currentprocess.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ where
147147
panic!("current process already set {old_p:?}");
148148
}
149149
*p.borrow_mut() = Some(process);
150-
let _guard = console_logger().set_default();
150+
let _guard = tracing_subscriber().set_default();
151151
let result = f();
152152
*p.borrow_mut() = None;
153153
result
@@ -164,7 +164,7 @@ fn ensure_hook() {
164164
});
165165
}
166166

167-
fn console_logger() -> impl tracing::Subscriber {
167+
fn tracing_subscriber() -> impl tracing::Subscriber {
168168
use tracing_subscriber::{
169169
filter::{EnvFilter, LevelFilter},
170170
layer::SubscriberExt,
@@ -251,7 +251,7 @@ pub fn with_runtime<'a, R>(
251251
panic!("current process already set {old_p:?}");
252252
}
253253
*p.borrow_mut() = Some(process);
254-
let result = runtime.block_on(fut.with_subscriber(console_logger()));
254+
let result = runtime.block_on(fut.with_subscriber(tracing_subscriber()));
255255
*p.borrow_mut() = None;
256256
result
257257
})

0 commit comments

Comments
 (0)