@@ -13,6 +13,7 @@ use std::{cmp, env};
13
13
use anyhow:: { anyhow, Context , Result } ;
14
14
use git_testament:: { git_testament, render_testament} ;
15
15
use tracing:: { debug, error, info, trace, warn} ;
16
+ use tracing_subscriber:: { reload:: Handle , EnvFilter , Registry } ;
16
17
17
18
use super :: self_update;
18
19
use crate :: {
@@ -652,3 +653,31 @@ pub(crate) fn warn_if_host_is_emulated(process: &Process) {
652
653
warn ! ( "For best compatibility and performance you should reinstall rustup for your native CPU." ) ;
653
654
}
654
655
}
656
+
657
+ /// Updates the console logger level according to whether `quiet` or `verbose` is set to `true`.
658
+ ///
659
+ /// Does nothing if at least one of the following conditions is met:
660
+ /// - The `RUSTUP_LOG` environment variable is set.
661
+ /// - Both `quiet` and `verbose` are set to `true`.
662
+ pub ( super ) fn update_console_filter (
663
+ process : & Process ,
664
+ filter : & Handle < EnvFilter , Registry > ,
665
+ quiet : bool ,
666
+ verbose : bool ,
667
+ ) {
668
+ if process. var ( "RUSTUP_LOG" ) . is_ok ( ) {
669
+ return ;
670
+ }
671
+
672
+ let maybe_directives = match ( quiet, verbose) {
673
+ ( true , _) => Some ( "rustup=WARN" ) ,
674
+ ( _, true ) => Some ( "rustup=DEBUG" ) ,
675
+ ( _, _) => None ,
676
+ } ;
677
+
678
+ if let Some ( directives) = maybe_directives {
679
+ filter
680
+ . modify ( |it| * it = EnvFilter :: new ( directives) )
681
+ . expect ( "error reloading `EnvFilter` for console_logger" ) ;
682
+ }
683
+ }
0 commit comments