Skip to content

Commit 2142f7e

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

File tree

1 file changed

+1
-37
lines changed

1 file changed

+1
-37
lines changed

src/currentprocess.rs

+1-37
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
@@ -138,16 +136,13 @@ pub fn with<F, R>(process: Process, f: F) -> R
138136
where
139137
F: FnOnce() -> R,
140138
{
141-
use tracing_subscriber::util::SubscriberInitExt;
142-
143139
ensure_hook();
144140

145141
PROCESS.with(|p| {
146142
if let Some(old_p) = &*p.borrow() {
147143
panic!("current process already set {old_p:?}");
148144
}
149145
*p.borrow_mut() = Some(process);
150-
let _guard = tracing_subscriber().set_default();
151146
let result = f();
152147
*p.borrow_mut() = None;
153148
result
@@ -164,35 +159,6 @@ fn ensure_hook() {
164159
});
165160
}
166161

167-
fn tracing_subscriber() -> impl tracing::Subscriber {
168-
use tracing_subscriber::{
169-
filter::{EnvFilter, LevelFilter},
170-
layer::SubscriberExt,
171-
Layer, Registry,
172-
};
173-
174-
let curr_process = currentprocess::process();
175-
let maybe_directives = curr_process.var_os("RUST_LOG").clone();
176-
let logger = tracing_subscriber::fmt::layer()
177-
.with_writer(move || curr_process.stderr())
178-
.with_ansi(false);
179-
let console_logger = if let Some(directives) = maybe_directives {
180-
let env_filter = EnvFilter::builder()
181-
.with_default_directive(LevelFilter::INFO.into())
182-
.parse_lossy(directives.to_string_lossy());
183-
logger.compact().with_filter(env_filter).boxed()
184-
} else {
185-
// Receive log lines from Rustup only.
186-
let env_filter = EnvFilter::new("rustup=DEBUG");
187-
logger
188-
.event_format(crate::cli::log::EventFormatter)
189-
.with_filter(env_filter)
190-
.boxed()
191-
};
192-
// TODO: What about the original otel logger?
193-
Registry::default().with(console_logger)
194-
}
195-
196162
/// Run a function in the context of a process definition and a tokio runtime.
197163
///
198164
/// The process state is injected into a thread-local in every work thread of
@@ -203,8 +169,6 @@ pub fn with_runtime<'a, R>(
203169
mut runtime_builder: tokio::runtime::Builder,
204170
fut: impl Future<Output = R> + 'a,
205171
) -> R {
206-
use tracing::instrument::WithSubscriber;
207-
208172
ensure_hook();
209173

210174
let start_process = process.clone();
@@ -251,7 +215,7 @@ pub fn with_runtime<'a, R>(
251215
panic!("current process already set {old_p:?}");
252216
}
253217
*p.borrow_mut() = Some(process);
254-
let result = runtime.block_on(fut.with_subscriber(tracing_subscriber()));
218+
let result = runtime.block_on(fut);
255219
*p.borrow_mut() = None;
256220
result
257221
})

0 commit comments

Comments
 (0)