From 4e875874b6fd22ddced8ee6807db6efa0d14ae9b Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sun, 13 Nov 2022 19:45:37 +1100 Subject: [PATCH] Replace use of `log` with `tracing` (#527) Resolved #522 * Add dep tracing v0.1.37 to binstalk * Use `tracing` instead of `log` for logging in binstalk * Rm dev dep `env_logger` since `log` is no longer used * Rm unused dep `log` from binstalk * Replace use of `log` with `tracing` in crates/bin * Enable feat std of dep log in crates/bin * Add dep tracing v0.1.37 to binstalk-downloader * Replace use of `log` with `tracing` in binstalk-downloader * Rm unused dep `log` from binstalk-downlaoder * Wrap `ops::{install, resolve}` in `tracing::instrument` * Wrap `Download::and_{extract, visit_tar}` in `instrument` Signed-off-by: Jiahao XU --- Cargo.lock | 36 ++++++++----------- crates/bin/Cargo.toml | 2 +- crates/bin/src/entry.rs | 3 +- crates/bin/src/install_path.rs | 2 +- crates/bin/src/main.rs | 2 +- crates/binstalk-downloader/Cargo.toml | 2 +- crates/binstalk-downloader/src/download.rs | 4 ++- .../src/download/async_extracter.rs | 2 +- .../src/download/extracter.rs | 2 +- crates/binstalk-downloader/src/remote.rs | 2 +- crates/binstalk/Cargo.toml | 5 +-- crates/binstalk/src/bins.rs | 2 +- crates/binstalk/src/drivers/crates_io.rs | 2 +- .../binstalk/src/drivers/crates_io/visitor.rs | 2 +- crates/binstalk/src/drivers/version.rs | 2 +- crates/binstalk/src/fetchers.rs | 1 - crates/binstalk/src/fetchers/gh_crate_meta.rs | 2 +- crates/binstalk/src/fetchers/quickinstall.rs | 2 +- crates/binstalk/src/fs.rs | 2 +- crates/binstalk/src/ops/install.rs | 3 +- crates/binstalk/src/ops/resolve.rs | 3 +- crates/binstalk/tests/parse-meta.rs | 2 -- 22 files changed, 38 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a6d0c038..ddeb5b20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -115,12 +115,10 @@ dependencies = [ "compact_str", "crates_io_api", "detect-targets", - "env_logger", "futures-util", "home", "itertools", "jobslot", - "log", "miette", "normalize-path", "once_cell", @@ -131,6 +129,7 @@ dependencies = [ "thiserror", "tinytemplate", "tokio", + "tracing", "url", "xz2", ] @@ -148,13 +147,13 @@ dependencies = [ "futures-util", "generic-array", "httpdate", - "log", "reqwest", "scopeguard", "tempfile", "thiserror", "tokio", "tower", + "tracing", "trust-dns-resolver", "url", "xz2", @@ -571,19 +570,6 @@ dependencies = [ "syn", ] -[[package]] -name = "env_logger" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - [[package]] name = "errno" version = "0.2.8" @@ -907,12 +893,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "hyper" version = "0.14.20" @@ -2199,6 +2179,7 @@ dependencies = [ "cfg-if", "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] @@ -2213,6 +2194,17 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "tracing-attributes" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tracing-core" version = "0.1.30" diff --git a/crates/bin/Cargo.toml b/crates/bin/Cargo.toml index 27560eca..4567dfc5 100644 --- a/crates/bin/Cargo.toml +++ b/crates/bin/Cargo.toml @@ -26,7 +26,7 @@ binstalk = { path = "../binstalk", version = "0.4.1" } clap = { version = "4.0.22", features = ["derive"] } crates_io_api = { version = "0.8.1", default-features = false } dirs = "4.0.0" -log = "0.4.17" +log = { version = "0.4.17", features = ["std"] } miette = "5.4.1" mimalloc = { version = "0.1.31", default-features = false, optional = true } once_cell = "1.16.0" diff --git a/crates/bin/src/entry.rs b/crates/bin/src/entry.rs index ee2ae23c..649a72ff 100644 --- a/crates/bin/src/entry.rs +++ b/crates/bin/src/entry.rs @@ -13,9 +13,10 @@ use binstalk::{ resolve::{CrateName, Resolution, VersionReqExt}, }, }; -use log::{debug, error, info, warn, LevelFilter}; +use log::LevelFilter; use miette::{miette, Result, WrapErr}; use tokio::task::block_in_place; +use tracing::{debug, error, info, warn}; use crate::{ args::{Args, Strategy}, diff --git a/crates/bin/src/install_path.rs b/crates/bin/src/install_path.rs index 50a3849e..042fee29 100644 --- a/crates/bin/src/install_path.rs +++ b/crates/bin/src/install_path.rs @@ -5,7 +5,7 @@ use std::{ }; use binstalk::home::cargo_home; -use log::debug; +use tracing::debug; pub fn get_cargo_roots_path(cargo_roots: Option) -> Option { if let Some(p) = cargo_roots { diff --git a/crates/bin/src/main.rs b/crates/bin/src/main.rs index fff42ee5..9e57b764 100644 --- a/crates/bin/src/main.rs +++ b/crates/bin/src/main.rs @@ -1,7 +1,7 @@ use std::time::Instant; use binstalk::helpers::jobserver_client::LazyJobserverClient; -use log::debug; +use tracing::debug; use cargo_binstall::{ args, diff --git a/crates/binstalk-downloader/Cargo.toml b/crates/binstalk-downloader/Cargo.toml index bbc18ba7..86764ee4 100644 --- a/crates/binstalk-downloader/Cargo.toml +++ b/crates/binstalk-downloader/Cargo.toml @@ -18,7 +18,6 @@ flate2 = { version = "1.0.24", default-features = false } futures-util = { version = "0.3.25", default-features = false, features = ["std"] } generic-array = "0.14.6" httpdate = "1.0.2" -log = { version = "0.4.17", features = ["std"] } reqwest = { version = "0.11.12", features = ["stream", "gzip", "brotli", "deflate"], default-features = false } scopeguard = "1.1.0" # Use a fork here since we need PAX support, but the upstream @@ -30,6 +29,7 @@ tempfile = "3.3.0" thiserror = "1.0.37" tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread", "sync", "time"], default-features = false } tower = { version = "0.4.13", features = ["limit", "util"] } +tracing = "0.1.37" trust-dns-resolver = { version = "0.21.2", optional = true, default-features = false, features = ["dnssec-ring"] } url = "2.3.1" diff --git a/crates/binstalk-downloader/src/download.rs b/crates/binstalk-downloader/src/download.rs index 6b3985e1..276d5a39 100644 --- a/crates/binstalk-downloader/src/download.rs +++ b/crates/binstalk-downloader/src/download.rs @@ -2,8 +2,8 @@ use std::{fmt::Debug, future::Future, io, marker::PhantomData, path::Path, pin:: use binstalk_manifests::cargo_toml_binstall::{PkgFmtDecomposed, TarBasedFmt}; use digest::{Digest, FixedOutput, HashMarker, Output, OutputSizeUser, Update}; -use log::debug; use thiserror::Error as ThisError; +use tracing::{debug, instrument}; pub use binstalk_manifests::cargo_toml_binstall::PkgFmt; pub use tar::Entries; @@ -92,6 +92,7 @@ impl Download { /// /// `cancellation_future` can be used to cancel the extraction and return /// [`DownloadError::UserAbort`] error. + #[instrument(skip(visitor, cancellation_future))] pub async fn and_visit_tar( self, fmt: TarBasedFmt, @@ -114,6 +115,7 @@ impl Download { /// /// `cancellation_future` can be used to cancel the extraction and return /// [`DownloadError::UserAbort`] error. + #[instrument(skip(path, cancellation_future))] pub async fn and_extract( self, fmt: PkgFmt, diff --git a/crates/binstalk-downloader/src/download/async_extracter.rs b/crates/binstalk-downloader/src/download/async_extracter.rs index bcaaa925..b36deed9 100644 --- a/crates/binstalk-downloader/src/download/async_extracter.rs +++ b/crates/binstalk-downloader/src/download/async_extracter.rs @@ -7,11 +7,11 @@ use std::{ use bytes::Bytes; use futures_util::stream::Stream; -use log::debug; use scopeguard::{guard, ScopeGuard}; use tar::Entries; use tempfile::tempfile; use tokio::task::block_in_place; +use tracing::debug; use super::{ extracter::*, stream_readable::StreamReadable, CancellationFuture, DownloadError, TarBasedFmt, diff --git a/crates/binstalk-downloader/src/download/extracter.rs b/crates/binstalk-downloader/src/download/extracter.rs index 096eca79..c33e9081 100644 --- a/crates/binstalk-downloader/src/download/extracter.rs +++ b/crates/binstalk-downloader/src/download/extracter.rs @@ -6,8 +6,8 @@ use std::{ use bzip2::bufread::BzDecoder; use flate2::bufread::GzDecoder; -use log::debug; use tar::Archive; +use tracing::debug; use xz2::bufread::XzDecoder; use zip::read::ZipArchive; use zstd::stream::Decoder as ZstdDecoder; diff --git a/crates/binstalk-downloader/src/remote.rs b/crates/binstalk-downloader/src/remote.rs index bfe68409..1be1d4e4 100644 --- a/crates/binstalk-downloader/src/remote.rs +++ b/crates/binstalk-downloader/src/remote.rs @@ -8,7 +8,6 @@ use std::{ use bytes::Bytes; use futures_util::stream::{Stream, StreamExt}; use httpdate::parse_http_date; -use log::{debug, info}; use reqwest::{ header::{HeaderMap, RETRY_AFTER}, Request, Response, StatusCode, @@ -16,6 +15,7 @@ use reqwest::{ use thiserror::Error as ThisError; use tokio::{sync::Mutex, time::sleep}; use tower::{limit::rate::RateLimit, Service, ServiceBuilder, ServiceExt}; +use tracing::{debug, info}; pub use reqwest::{tls, Error as ReqwestError, Method}; pub use url::Url; diff --git a/crates/binstalk/Cargo.toml b/crates/binstalk/Cargo.toml index 759cb110..87e259d0 100644 --- a/crates/binstalk/Cargo.toml +++ b/crates/binstalk/Cargo.toml @@ -21,7 +21,6 @@ futures-util = { version = "0.3.25", default-features = false, features = ["std" home = "0.5.4" itertools = "0.10.5" jobslot = { version = "0.2.6", features = ["tokio"] } -log = { version = "0.4.17", features = ["std"] } miette = "5.4.1" normalize-path = { version = "0.2.0", path = "../normalize-path" } once_cell = "1.16.0" @@ -33,12 +32,10 @@ thiserror = "1.0.37" tinytemplate = "1.2.1" # parking_lot for `tokio::sync::OnceCell::const_new` tokio = { version = "1.21.2", features = ["rt", "process", "sync", "signal", "parking_lot"], default-features = false } +tracing = "0.1.37" url = { version = "2.3.1", features = ["serde"] } xz2 = "0.1.7" -[dev-dependencies] -env_logger = "0.9.3" - [features] default = ["static", "rustls"] diff --git a/crates/binstalk/src/bins.rs b/crates/binstalk/src/bins.rs index 8961d89d..21b58fcb 100644 --- a/crates/binstalk/src/bins.rs +++ b/crates/binstalk/src/bins.rs @@ -6,10 +6,10 @@ use std::{ use cargo_toml::Product; use compact_str::CompactString; -use log::debug; use normalize_path::NormalizePath; use serde::Serialize; use tinytemplate::TinyTemplate; +use tracing::debug; use crate::{ errors::BinstallError, diff --git a/crates/binstalk/src/drivers/crates_io.rs b/crates/binstalk/src/drivers/crates_io.rs index 6fbcbec8..1847b204 100644 --- a/crates/binstalk/src/drivers/crates_io.rs +++ b/crates/binstalk/src/drivers/crates_io.rs @@ -2,8 +2,8 @@ use std::path::PathBuf; use cargo_toml::Manifest; use crates_io_api::AsyncClient; -use log::debug; use semver::VersionReq; +use tracing::debug; use crate::{ errors::BinstallError, diff --git a/crates/binstalk/src/drivers/crates_io/visitor.rs b/crates/binstalk/src/drivers/crates_io/visitor.rs index b6d082c3..36abe991 100644 --- a/crates/binstalk/src/drivers/crates_io/visitor.rs +++ b/crates/binstalk/src/drivers/crates_io/visitor.rs @@ -4,8 +4,8 @@ use std::{ }; use cargo_toml::Manifest; -use log::debug; use normalize_path::NormalizePath; +use tracing::debug; use super::vfs::Vfs; use crate::{ diff --git a/crates/binstalk/src/drivers/version.rs b/crates/binstalk/src/drivers/version.rs index 4b8b7413..3861d360 100644 --- a/crates/binstalk/src/drivers/version.rs +++ b/crates/binstalk/src/drivers/version.rs @@ -1,5 +1,5 @@ -use log::debug; use semver::VersionReq; +use tracing::debug; use crate::errors::BinstallError; diff --git a/crates/binstalk/src/fetchers.rs b/crates/binstalk/src/fetchers.rs index 603c1b3d..6e606340 100644 --- a/crates/binstalk/src/fetchers.rs +++ b/crates/binstalk/src/fetchers.rs @@ -2,7 +2,6 @@ use std::{path::Path, sync::Arc}; use compact_str::CompactString; pub use gh_crate_meta::*; -pub use log::debug; pub use quickinstall::*; use crate::{ diff --git a/crates/binstalk/src/fetchers/gh_crate_meta.rs b/crates/binstalk/src/fetchers/gh_crate_meta.rs index 63ced201..896582e4 100644 --- a/crates/binstalk/src/fetchers/gh_crate_meta.rs +++ b/crates/binstalk/src/fetchers/gh_crate_meta.rs @@ -2,11 +2,11 @@ use std::{path::Path, sync::Arc}; use compact_str::{CompactString, ToCompactString}; use futures_util::stream::{FuturesUnordered, StreamExt}; -use log::{debug, warn}; use once_cell::sync::OnceCell; use serde::Serialize; use strum::IntoEnumIterator; use tinytemplate::TinyTemplate; +use tracing::{debug, warn}; use url::Url; use crate::{ diff --git a/crates/binstalk/src/fetchers/quickinstall.rs b/crates/binstalk/src/fetchers/quickinstall.rs index e374b143..9821ba8e 100644 --- a/crates/binstalk/src/fetchers/quickinstall.rs +++ b/crates/binstalk/src/fetchers/quickinstall.rs @@ -1,8 +1,8 @@ use std::{path::Path, sync::Arc}; use compact_str::CompactString; -use log::debug; use tokio::task::JoinHandle; +use tracing::debug; use url::Url; use crate::{ diff --git a/crates/binstalk/src/fs.rs b/crates/binstalk/src/fs.rs index 3962b249..270f6872 100644 --- a/crates/binstalk/src/fs.rs +++ b/crates/binstalk/src/fs.rs @@ -1,7 +1,7 @@ use std::{fs, io, path::Path}; -use log::debug; use tempfile::NamedTempFile; +use tracing::debug; /// Atomically install a file. /// diff --git a/crates/binstalk/src/ops/install.rs b/crates/binstalk/src/ops/install.rs index 2e1fe3d1..8fbca294 100644 --- a/crates/binstalk/src/ops/install.rs +++ b/crates/binstalk/src/ops/install.rs @@ -1,8 +1,8 @@ use std::{borrow::Cow, env, ffi::OsStr, sync::Arc}; use compact_str::CompactString; -use log::{debug, error, info}; use tokio::{process::Command, task::block_in_place}; +use tracing::{debug, error, info, instrument}; use super::{resolve::Resolution, Options}; use crate::{ @@ -12,6 +12,7 @@ use crate::{ manifests::crate_info::{CrateInfo, CrateSource}, }; +#[instrument(skip_all)] pub async fn install( resolution: Resolution, opts: Arc, diff --git a/crates/binstalk/src/ops/resolve.rs b/crates/binstalk/src/ops/resolve.rs index 1e494e5c..6401f55a 100644 --- a/crates/binstalk/src/ops/resolve.rs +++ b/crates/binstalk/src/ops/resolve.rs @@ -9,9 +9,9 @@ use std::{ use cargo_toml::{Manifest, Package, Product}; use compact_str::{CompactString, ToCompactString}; use itertools::Itertools; -use log::{debug, info, warn}; use semver::{Version, VersionReq}; use tokio::task::block_in_place; +use tracing::{debug, info, instrument, warn}; use super::Options; use crate::{ @@ -89,6 +89,7 @@ impl Resolution { } } +#[instrument(skip_all)] pub async fn resolve( opts: Arc, crate_name: CrateName, diff --git a/crates/binstalk/tests/parse-meta.rs b/crates/binstalk/tests/parse-meta.rs index 2d9486fc..a76bedf5 100644 --- a/crates/binstalk/tests/parse-meta.rs +++ b/crates/binstalk/tests/parse-meta.rs @@ -3,8 +3,6 @@ use cargo_toml::Product; #[test] fn parse_meta() { - let _ = env_logger::builder().is_test(true).try_init(); - let mut manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); manifest_dir.push_str("/tests/parse-meta.Cargo.toml");