Skip to content

Commit f0dc6e2

Browse files
authored
Merge branch 'main' into fix/multichoice-hint
2 parents a7115be + 787f427 commit f0dc6e2

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

crates/vite_shared/src/tracing.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Tracing initialization for vite-plus
22
3-
use std::sync::OnceLock;
3+
use std::{str::FromStr, sync::OnceLock};
44

55
use tracing_subscriber::{
66
filter::{LevelFilter, Targets},
@@ -14,25 +14,28 @@ use crate::env_vars;
1414
/// Uses `OnceLock` to ensure tracing is only initialized once,
1515
/// even if called multiple times.
1616
///
17+
/// Only sets the global default subscriber when `VITE_LOG` is set.
18+
/// When unset, the global default slot is left free so that other
19+
/// subscribers (e.g., rolldown devtools) can claim it without panicking.
20+
///
1721
/// # Environment Variables
1822
/// - `VITE_LOG`: Controls log filtering (e.g., "debug", "vite_task=trace")
1923
pub fn init_tracing() {
2024
static TRACING: OnceLock<()> = OnceLock::new();
2125
TRACING.get_or_init(|| {
26+
let Ok(env_var) = std::env::var(env_vars::VITE_LOG) else {
27+
return;
28+
};
29+
2230
tracing_subscriber::registry()
2331
.with(
24-
std::env::var(env_vars::VITE_LOG)
25-
.map_or_else(
26-
|_| Targets::new(),
27-
|env_var| {
28-
use std::str::FromStr;
29-
Targets::from_str(&env_var).unwrap_or_default()
30-
},
31-
)
32+
Targets::from_str(&env_var)
33+
.unwrap_or_default()
3234
// disable brush-parser tracing
3335
.with_targets([("tokenize", LevelFilter::OFF), ("parse", LevelFilter::OFF)]),
3436
)
3537
.with(tracing_subscriber::fmt::layer())
36-
.init();
38+
.try_init()
39+
.ok();
3740
});
3841
}

0 commit comments

Comments
 (0)