@@ -15,8 +15,20 @@ use bootstrap::{
15
15
human_readable_changes, t,
16
16
} ;
17
17
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" ) ) ]
19
28
fn main ( ) {
29
+ #[ cfg( feature = "tracing" ) ]
30
+ setup_tracing ( ) ;
31
+
20
32
let args = env:: args ( ) . skip ( 1 ) . collect :: < Vec < _ > > ( ) ;
21
33
22
34
if Flags :: try_parse_verbose_help ( & args) {
@@ -187,3 +199,19 @@ fn check_version(config: &Config) -> Option<String> {
187
199
188
200
Some ( msg)
189
201
}
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