Skip to content

Commit 4c9664b

Browse files
committed
bootstrap: add tracing and tracing-tree based tracing setup
1 parent 63895e1 commit 4c9664b

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/bootstrap/src/bin/main.rs

+29-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,20 @@ use bootstrap::{
1515
human_readable_changes, t,
1616
};
1717
use build_helper::ci::CiEnv;
18-
18+
// NOTE: These are conditionally enabled if the user specifies `BOOTSTRAP_TRACING=...`, which builds
19+
// bootstrap with `--features=tracing`.
20+
#[cfg(feature = "tracing")]
21+
use tracing::*;
22+
#[cfg(feature = "tracing")]
23+
use tracing_subscriber::EnvFilter;
24+
#[cfg(feature = "tracing")]
25+
use tracing_subscriber::prelude::*;
26+
27+
#[cfg_attr(feature = "tracing", instrument(level = "trace", name = "main"))]
1928
fn main() {
29+
#[cfg(feature = "tracing")]
30+
setup_tracing();
31+
2032
let args = env::args().skip(1).collect::<Vec<_>>();
2133

2234
if Flags::try_parse_verbose_help(&args) {
@@ -187,3 +199,19 @@ fn check_version(config: &Config) -> Option<String> {
187199

188200
Some(msg)
189201
}
202+
203+
#[cfg(feature = "tracing")]
204+
fn setup_tracing() {
205+
let filter = EnvFilter::from_env("BOOTSTRAP_TRACING");
206+
let layer = tracing_tree::HierarchicalLayer::default()
207+
.with_writer(std::io::stderr)
208+
.with_ansi(true)
209+
.with_targets(true)
210+
.with_bracketed_fields(true)
211+
.with_indent_amount(2)
212+
.with_indent_lines(true);
213+
let subscriber = tracing_subscriber::registry().with(filter).with(layer);
214+
215+
tracing::subscriber::set_global_default(subscriber).unwrap();
216+
trace!("tracing subscriber setup");
217+
}

0 commit comments

Comments
 (0)