Skip to content

Commit cea0ef7

Browse files
committed
refactor(cli/setup-mode): extract update_console_logger()
1 parent 09e51dd commit cea0ef7

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

src/cli/common.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::{cmp, env};
1313
use anyhow::{anyhow, Context, Result};
1414
use git_testament::{git_testament, render_testament};
1515
use tracing::{debug, error, info, trace, warn};
16+
use tracing_subscriber::{reload::Handle, EnvFilter, Registry};
1617

1718
use super::self_update;
1819
use crate::{
@@ -652,3 +653,26 @@ 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 `quiet` or `verbose`
658+
/// if the `RUSTUP_LOG` environment variable is unset.
659+
pub(super) fn update_console_filter(
660+
process: &Process,
661+
filter: &Handle<EnvFilter, Registry>,
662+
quiet: bool,
663+
verbose: bool,
664+
) {
665+
if process.var("RUSTUP_LOG").is_ok() {
666+
return;
667+
}
668+
if quiet {
669+
filter
670+
.modify(|it| *it = EnvFilter::new("rustup=WARN"))
671+
.expect("error reloading `EnvFilter` for console_logger");
672+
}
673+
if verbose {
674+
filter
675+
.modify(|it| *it = EnvFilter::new("rustup=DEBUG"))
676+
.expect("error reloading `EnvFilter` for console_logger");
677+
}
678+
}

src/cli/setup_mode.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use tracing_subscriber::{reload::Handle, EnvFilter, Registry};
77

88
use crate::{
99
cli::{
10-
common,
10+
common::{self, update_console_filter},
1111
self_update::{self, InstallOpts},
1212
},
1313
dist::Profile,
@@ -115,18 +115,7 @@ pub async fn main(
115115
warn!("{}", common::WARN_COMPLETE_PROFILE);
116116
}
117117

118-
if process.var("RUSTUP_LOG").is_err() {
119-
if quiet {
120-
console_filter
121-
.modify(|it| *it = EnvFilter::new("rustup=WARN"))
122-
.expect("error reloading `EnvFilter` for console_logger");
123-
}
124-
if verbose {
125-
console_filter
126-
.modify(|it| *it = EnvFilter::new("rustup=DEBUG"))
127-
.expect("error reloading `EnvFilter` for console_logger");
128-
}
129-
}
118+
update_console_filter(process, &console_filter, quiet, verbose);
130119

131120
let opts = InstallOpts {
132121
default_host_triple: default_host,

0 commit comments

Comments
 (0)