Skip to content

Commit 6d54875

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

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
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

+4-6
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ use cwdsource::*;
3232
use filesource::*;
3333
use varsource::*;
3434

35-
use crate::currentprocess;
36-
3735
/// An abstraction for the current process.
3836
///
3937
/// This acts as a clonable proxy to the global state provided by some key OS
@@ -147,7 +145,7 @@ where
147145
panic!("current process already set {old_p:?}");
148146
}
149147
*p.borrow_mut() = Some(process);
150-
let _guard = console_logger().set_default();
148+
let _guard = tracing_subscriber().set_default();
151149
let result = f();
152150
*p.borrow_mut() = None;
153151
result
@@ -164,14 +162,14 @@ fn ensure_hook() {
164162
});
165163
}
166164

167-
fn console_logger() -> impl tracing::Subscriber {
165+
fn tracing_subscriber() -> impl tracing::Subscriber {
168166
use tracing_subscriber::{
169167
filter::{EnvFilter, LevelFilter},
170168
layer::SubscriberExt,
171169
Layer, Registry,
172170
};
173171

174-
let curr_process = currentprocess::process();
172+
let curr_process = process();
175173
let maybe_directives = curr_process.var_os("RUST_LOG").clone();
176174
let logger = tracing_subscriber::fmt::layer()
177175
.with_writer(move || curr_process.stderr())
@@ -251,7 +249,7 @@ pub fn with_runtime<'a, R>(
251249
panic!("current process already set {old_p:?}");
252250
}
253251
*p.borrow_mut() = Some(process);
254-
let result = runtime.block_on(fut.with_subscriber(console_logger()));
252+
let result = runtime.block_on(fut.with_subscriber(tracing_subscriber()));
255253
*p.borrow_mut() = None;
256254
result
257255
})

0 commit comments

Comments
 (0)