@@ -13,6 +13,7 @@ use std::{cmp, env};
1313use anyhow:: { anyhow, Context , Result } ;
1414use git_testament:: { git_testament, render_testament} ;
1515use tracing:: { debug, error, info, trace, warn} ;
16+ use tracing_subscriber:: { reload:: Handle , EnvFilter , Registry } ;
1617
1718use super :: self_update;
1819use crate :: {
@@ -652,3 +653,31 @@ pub(crate) fn warn_if_host_is_emulated(process: &Process) {
652653 warn ! ( "For best compatibility and performance you should reinstall rustup for your native CPU." ) ;
653654 }
654655}
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