Skip to content

Commit d6c57b2

Browse files
committed
bootstrap: add tracing and tracing-tree based tracing setup
1 parent 1292733 commit d6c57b2

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/bootstrap/src/bin/main.rs

Lines changed: 29 additions & 1 deletion
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+
// These are conditionally enabled if the user specifies `BOOTSTRAP_LOG=...`, which builds bootstrap
19+
// with `--features=logging`.
20+
#[cfg(feature = "logging")]
21+
use tracing::*;
22+
#[cfg(feature = "logging")]
23+
use tracing_subscriber::EnvFilter;
24+
#[cfg(feature = "logging")]
25+
use tracing_subscriber::prelude::*;
26+
27+
#[cfg_attr(feature = "logging", instrument(level = "trace", name = "main"))]
1928
fn main() {
29+
#[cfg(feature = "logging")]
30+
setup_logging();
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 = "logging")]
204+
fn setup_logging() {
205+
let filter = EnvFilter::from_env("BOOTSTRAP_LOG");
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)