Skip to content

Commit fae9a26

Browse files
djcrami3l
authored andcommitted
Use tracing macros directly
1 parent a10ad73 commit fae9a26

File tree

11 files changed

+33
-43
lines changed

11 files changed

+33
-43
lines changed

src/cli/common.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::{cmp, env};
1111
use anyhow::{anyhow, Context, Result};
1212
use git_testament::{git_testament, render_testament};
1313
use once_cell::sync::Lazy;
14+
use tracing::{debug, error, info, trace, warn};
1415

1516
use super::self_update;
1617
use crate::cli::download_tracker::DownloadTracker;
@@ -159,7 +160,7 @@ impl Notifier {
159160
match level {
160161
NotificationLevel::Verbose => {
161162
if self.verbose {
162-
verbose!("{}", n);
163+
debug!("{}", n);
163164
}
164165
}
165166
NotificationLevel::Info => {
@@ -169,10 +170,10 @@ impl Notifier {
169170
warn!("{}", n);
170171
}
171172
NotificationLevel::Error => {
172-
err!("{}", n);
173+
error!("{}", n);
173174
}
174175
NotificationLevel::Debug => {
175-
debug!("{}", n);
176+
trace!("{}", n);
176177
}
177178
}
178179
}
@@ -338,7 +339,7 @@ pub(crate) fn self_update_permitted(explicit: bool) -> Result<SelfUpdatePermissi
338339
{
339340
match e.kind() {
340341
ErrorKind::PermissionDenied => {
341-
debug!("Skipping self-update because we cannot write to the rustup dir");
342+
trace!("Skipping self-update because we cannot write to the rustup dir");
342343
if explicit {
343344
return Ok(SelfUpdatePermission::HardFail);
344345
} else {
@@ -359,7 +360,7 @@ where
359360
{
360361
match self_update_permitted(false)? {
361362
SelfUpdatePermission::HardFail => {
362-
err!("Unable to self-update. STOP");
363+
error!("Unable to self-update. STOP");
363364
return Ok(utils::ExitCode(1));
364365
}
365366
SelfUpdatePermission::Skip => return Ok(utils::ExitCode(0)),
@@ -604,9 +605,9 @@ pub fn report_error(e: &anyhow::Error, process: &Process) {
604605
// hunk to revisit, that and a similar build.rs auto-detect glue as anyhow
605606
// has to detect when backtrace is available.
606607
if show_backtrace(process) {
607-
err!("{:?}", e);
608+
error!("{:?}", e);
608609
} else {
609-
err!("{:#}", e);
610+
error!("{:#}", e);
610611
}
611612
}
612613

src/cli/job.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ mod imp {
4040
use std::mem;
4141
use std::ptr;
4242

43+
use tracing::info;
4344
use windows_sys::Win32::Foundation::*;
4445
use windows_sys::Win32::System::JobObjects::*;
4546
use windows_sys::Win32::System::Threading::*;

src/cli/log.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,6 @@ use opentelemetry_sdk::trace::Tracer;
1818

1919
use crate::{currentprocess::Process, utils::notify::NotificationLevel};
2020

21-
macro_rules! debug {
22-
( $ ( $ arg : tt ) * ) => ( ::tracing::trace ! ( $ ( $ arg ) * ) )
23-
}
24-
25-
macro_rules! verbose {
26-
( $ ( $ arg : tt ) * ) => ( ::tracing::debug ! ( $ ( $ arg ) * ) )
27-
}
28-
29-
macro_rules! info {
30-
( $ ( $ arg : tt ) * ) => ( ::tracing::info ! ( $ ( $ arg ) * ) )
31-
}
32-
33-
macro_rules! warn {
34-
( $ ( $ arg : tt ) * ) => ( ::tracing::warn ! ( $ ( $ arg ) * ) )
35-
}
36-
37-
macro_rules! err {
38-
( $ ( $ arg : tt ) * ) => ( ::tracing::error ! ( $ ( $ arg ) * ) )
39-
}
40-
4121
pub fn tracing_subscriber(process: &Process) -> impl tracing::Subscriber {
4222
use tracing_subscriber::{layer::SubscriberExt, Registry};
4323

src/cli/rustup_mode.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use anyhow::{anyhow, Error, Result};
88
use clap::{builder::PossibleValue, Args, CommandFactory, Parser, Subcommand, ValueEnum};
99
use clap_complete::Shell;
1010
use itertools::Itertools;
11+
use tracing::{error, info, trace, warn};
1112

1213
use crate::{
1314
cli::{
@@ -548,7 +549,7 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result<utils::Exit
548549
let cfg = &mut common::set_globals(current_dir, false, true, process)?;
549550

550551
if let Some(t) = process.args().find(|x| x.starts_with('+')) {
551-
debug!("Fetching rustc version from toolchain `{}`", t);
552+
trace!("Fetching rustc version from toolchain `{}`", t);
552553
cfg.set_toolchain_override(&ResolvableToolchainName::try_from(&t[1..])?);
553554
}
554555

@@ -559,7 +560,7 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result<utils::Exit
559560

560561
match rustc_version(current_dir, process).await {
561562
Ok(version) => info!("The currently active `rustc` version is `{}`", version),
562-
Err(err) => debug!("Wanted to tell you the current rustc version, too, but ran into this error: {}", err),
563+
Err(err) => trace!("Wanted to tell you the current rustc version, too, but ran into this error: {}", err),
563564
}
564565
return Ok(utils::ExitCode(0));
565566
}
@@ -828,7 +829,7 @@ async fn update(cfg: &mut Cfg<'_>, opts: UpdateOpts) -> Result<utils::ExitCode>
828829

829830
let target_triple = name.clone().resolve(&host_arch)?.target;
830831
if !forced && !host_arch.can_run(&target_triple)? {
831-
err!("DEPRECATED: future versions of rustup will require --force-non-host to install a non-host toolchain.");
832+
error!("DEPRECATED: future versions of rustup will require --force-non-host to install a non-host toolchain.");
832833
warn!("toolchain '{name}' may not be able to run on this system.");
833834
warn!(
834835
"If you meant to build software to target that platform, perhaps try `rustup target add {}` instead?",

src/cli/self_update.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ use clap::ValueEnum;
6161
use itertools::Itertools;
6262
use same_file::Handle;
6363
use serde::{Deserialize, Serialize};
64+
use tracing::{error, info, trace, warn};
6465

6566
use crate::currentprocess::terminalsource;
6667
use crate::errors::RustupError;
@@ -237,7 +238,7 @@ impl<'a> InstallOpts<'a> {
237238
Some(MaybeOfficialToolchainName::Some(s)) => s.into(),
238239
};
239240
let resolved = partial_channel.resolve(&host_triple)?;
240-
debug!("Successfully resolved installation toolchain as: {resolved}");
241+
trace!("Successfully resolved installation toolchain as: {resolved}");
241242
Ok(())
242243
}
243244
}
@@ -497,7 +498,7 @@ static DEFAULT_UPDATE_ROOT: &str = "https://static.rust-lang.org/rustup";
497498
fn update_root(process: &Process) -> String {
498499
process
499500
.var("RUSTUP_UPDATE_ROOT")
500-
.inspect(|url| debug!("`RUSTUP_UPDATE_ROOT` has been set to `{url}`"))
501+
.inspect(|url| trace!("`RUSTUP_UPDATE_ROOT` has been set to `{url}`"))
501502
.unwrap_or_else(|_| String::from(DEFAULT_UPDATE_ROOT))
502503
}
503504

@@ -985,8 +986,8 @@ async fn maybe_install_rust(
985986

986987
pub(crate) fn uninstall(no_prompt: bool, process: &Process) -> Result<utils::ExitCode> {
987988
if NEVER_SELF_UPDATE {
988-
err!("self-uninstall is disabled for this build of rustup");
989-
err!("you should probably use your system package manager to uninstall rustup");
989+
error!("self-uninstall is disabled for this build of rustup");
990+
error!("you should probably use your system package manager to uninstall rustup");
990991
return Ok(utils::ExitCode(1));
991992
}
992993

@@ -1112,8 +1113,8 @@ pub(crate) async fn update(cfg: &Cfg<'_>) -> Result<utils::ExitCode> {
11121113
match update_permitted {
11131114
HardFail => {
11141115
// TODO: Detect which package manager and be more useful.
1115-
err!("self-update is disabled for this build of rustup");
1116-
err!("you should probably use your system package manager to update rustup");
1116+
error!("self-update is disabled for this build of rustup");
1117+
error!("you should probably use your system package manager to update rustup");
11171118
return Ok(utils::ExitCode(1));
11181119
}
11191120
Skip => {
@@ -1126,7 +1127,7 @@ pub(crate) async fn update(cfg: &Cfg<'_>) -> Result<utils::ExitCode> {
11261127
match prepare_update(cfg.process).await? {
11271128
Some(setup_path) => {
11281129
let Some(version) = get_and_parse_new_rustup_version(&setup_path) else {
1129-
err!("failed to get rustup version");
1130+
error!("failed to get rustup version");
11301131
return Ok(utils::ExitCode(1));
11311132
};
11321133

src/cli/self_update/unix.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::path::{Path, PathBuf};
22
use std::process::Command;
33

44
use anyhow::{bail, Context, Result};
5+
use tracing::{error, warn};
56

67
use super::install_bins;
78
use super::shell;
@@ -34,11 +35,11 @@ pub(crate) fn do_anti_sudo_check(no_prompt: bool, process: &Process) -> Result<u
3435
match home_mismatch(process) {
3536
(false, _, _) => {}
3637
(true, env_home, euid_home) => {
37-
err!("$HOME differs from euid-obtained home directory: you may be using sudo");
38-
err!("$HOME directory: {}", env_home.display());
39-
err!("euid-obtained home directory: {}", euid_home.display());
38+
error!("$HOME differs from euid-obtained home directory: you may be using sudo");
39+
error!("$HOME directory: {}", env_home.display());
40+
error!("euid-obtained home directory: {}", euid_home.display());
4041
if !no_prompt {
41-
err!("if this is what you want, restart the installation with `-y'");
42+
error!("if this is what you want, restart the installation with `-y'");
4243
return Ok(utils::ExitCode(1));
4344
}
4445
}

src/cli/self_update/windows.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::process::Command;
88
use std::sync::{Arc, Mutex};
99

1010
use anyhow::{anyhow, Context, Result};
11+
use tracing::{info, warn};
1112

1213
use super::super::errors::*;
1314
use super::common;

src/cli/setup_mode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::path::PathBuf;
22

33
use anyhow::Result;
44
use clap::Parser;
5+
use tracing::warn;
56

67
use crate::{
78
cli::{

src/config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use anyhow::{anyhow, bail, Context, Result};
99
use serde::Deserialize;
1010
use thiserror::Error as ThisError;
1111
use tokio_stream::StreamExt;
12+
use tracing::trace;
1213

1314
use crate::settings::MetadataVersion;
1415
use crate::{
@@ -297,7 +298,7 @@ impl<'a> Cfg<'a> {
297298

298299
let dist_root_server = match process.var("RUSTUP_DIST_SERVER") {
299300
Ok(s) if !s.is_empty() => {
300-
debug!("`RUSTUP_DIST_SERVER` has been set to `{s}`");
301+
trace!("`RUSTUP_DIST_SERVER` has been set to `{s}`");
301302
s
302303
}
303304
_ => {
@@ -306,7 +307,7 @@ impl<'a> Cfg<'a> {
306307
.var("RUSTUP_DIST_ROOT")
307308
.ok()
308309
.and_then(utils::if_not_empty)
309-
.inspect(|url| debug!("`RUSTUP_DIST_ROOT` has been set to `{url}`"))
310+
.inspect(|url| trace!("`RUSTUP_DIST_ROOT` has been set to `{url}`"))
310311
.map_or(Cow::Borrowed(dist::DEFAULT_DIST_ROOT), Cow::Owned)
311312
.as_ref()
312313
.trim_end_matches("/dist")

src/dist/component/package.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::path::{Path, PathBuf};
1010

1111
use anyhow::{anyhow, bail, Context, Result};
1212
use tar::EntryType;
13+
use tracing::warn;
1314

1415
use crate::currentprocess::Process;
1516
use crate::diskio::{get_executor, CompletedIo, Executor, FileBuffer, Item, Kind, IO_CHUNK_SIZE};

0 commit comments

Comments
 (0)