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 <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-11-13 19:45:37 +11:00 committed by GitHub
parent 9e80cf0700
commit 4e875874b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 38 additions and 47 deletions

36
Cargo.lock generated
View file

@ -115,12 +115,10 @@ dependencies = [
"compact_str", "compact_str",
"crates_io_api", "crates_io_api",
"detect-targets", "detect-targets",
"env_logger",
"futures-util", "futures-util",
"home", "home",
"itertools", "itertools",
"jobslot", "jobslot",
"log",
"miette", "miette",
"normalize-path", "normalize-path",
"once_cell", "once_cell",
@ -131,6 +129,7 @@ dependencies = [
"thiserror", "thiserror",
"tinytemplate", "tinytemplate",
"tokio", "tokio",
"tracing",
"url", "url",
"xz2", "xz2",
] ]
@ -148,13 +147,13 @@ dependencies = [
"futures-util", "futures-util",
"generic-array", "generic-array",
"httpdate", "httpdate",
"log",
"reqwest", "reqwest",
"scopeguard", "scopeguard",
"tempfile", "tempfile",
"thiserror", "thiserror",
"tokio", "tokio",
"tower", "tower",
"tracing",
"trust-dns-resolver", "trust-dns-resolver",
"url", "url",
"xz2", "xz2",
@ -571,19 +570,6 @@ dependencies = [
"syn", "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]] [[package]]
name = "errno" name = "errno"
version = "0.2.8" version = "0.2.8"
@ -907,12 +893,6 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]] [[package]]
name = "hyper" name = "hyper"
version = "0.14.20" version = "0.14.20"
@ -2199,6 +2179,7 @@ dependencies = [
"cfg-if", "cfg-if",
"log", "log",
"pin-project-lite", "pin-project-lite",
"tracing-attributes",
"tracing-core", "tracing-core",
] ]
@ -2213,6 +2194,17 @@ dependencies = [
"tracing-subscriber", "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]] [[package]]
name = "tracing-core" name = "tracing-core"
version = "0.1.30" version = "0.1.30"

View file

@ -26,7 +26,7 @@ binstalk = { path = "../binstalk", version = "0.4.1" }
clap = { version = "4.0.22", features = ["derive"] } clap = { version = "4.0.22", features = ["derive"] }
crates_io_api = { version = "0.8.1", default-features = false } crates_io_api = { version = "0.8.1", default-features = false }
dirs = "4.0.0" dirs = "4.0.0"
log = "0.4.17" log = { version = "0.4.17", features = ["std"] }
miette = "5.4.1" miette = "5.4.1"
mimalloc = { version = "0.1.31", default-features = false, optional = true } mimalloc = { version = "0.1.31", default-features = false, optional = true }
once_cell = "1.16.0" once_cell = "1.16.0"

View file

@ -13,9 +13,10 @@ use binstalk::{
resolve::{CrateName, Resolution, VersionReqExt}, resolve::{CrateName, Resolution, VersionReqExt},
}, },
}; };
use log::{debug, error, info, warn, LevelFilter}; use log::LevelFilter;
use miette::{miette, Result, WrapErr}; use miette::{miette, Result, WrapErr};
use tokio::task::block_in_place; use tokio::task::block_in_place;
use tracing::{debug, error, info, warn};
use crate::{ use crate::{
args::{Args, Strategy}, args::{Args, Strategy},

View file

@ -5,7 +5,7 @@ use std::{
}; };
use binstalk::home::cargo_home; use binstalk::home::cargo_home;
use log::debug; use tracing::debug;
pub fn get_cargo_roots_path(cargo_roots: Option<PathBuf>) -> Option<PathBuf> { pub fn get_cargo_roots_path(cargo_roots: Option<PathBuf>) -> Option<PathBuf> {
if let Some(p) = cargo_roots { if let Some(p) = cargo_roots {

View file

@ -1,7 +1,7 @@
use std::time::Instant; use std::time::Instant;
use binstalk::helpers::jobserver_client::LazyJobserverClient; use binstalk::helpers::jobserver_client::LazyJobserverClient;
use log::debug; use tracing::debug;
use cargo_binstall::{ use cargo_binstall::{
args, args,

View file

@ -18,7 +18,6 @@ flate2 = { version = "1.0.24", default-features = false }
futures-util = { version = "0.3.25", default-features = false, features = ["std"] } futures-util = { version = "0.3.25", default-features = false, features = ["std"] }
generic-array = "0.14.6" generic-array = "0.14.6"
httpdate = "1.0.2" httpdate = "1.0.2"
log = { version = "0.4.17", features = ["std"] }
reqwest = { version = "0.11.12", features = ["stream", "gzip", "brotli", "deflate"], default-features = false } reqwest = { version = "0.11.12", features = ["stream", "gzip", "brotli", "deflate"], default-features = false }
scopeguard = "1.1.0" scopeguard = "1.1.0"
# Use a fork here since we need PAX support, but the upstream # Use a fork here since we need PAX support, but the upstream
@ -30,6 +29,7 @@ tempfile = "3.3.0"
thiserror = "1.0.37" thiserror = "1.0.37"
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread", "sync", "time"], default-features = false } tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread", "sync", "time"], default-features = false }
tower = { version = "0.4.13", features = ["limit", "util"] } 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"] } trust-dns-resolver = { version = "0.21.2", optional = true, default-features = false, features = ["dnssec-ring"] }
url = "2.3.1" url = "2.3.1"

View file

@ -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 binstalk_manifests::cargo_toml_binstall::{PkgFmtDecomposed, TarBasedFmt};
use digest::{Digest, FixedOutput, HashMarker, Output, OutputSizeUser, Update}; use digest::{Digest, FixedOutput, HashMarker, Output, OutputSizeUser, Update};
use log::debug;
use thiserror::Error as ThisError; use thiserror::Error as ThisError;
use tracing::{debug, instrument};
pub use binstalk_manifests::cargo_toml_binstall::PkgFmt; pub use binstalk_manifests::cargo_toml_binstall::PkgFmt;
pub use tar::Entries; pub use tar::Entries;
@ -92,6 +92,7 @@ impl Download {
/// ///
/// `cancellation_future` can be used to cancel the extraction and return /// `cancellation_future` can be used to cancel the extraction and return
/// [`DownloadError::UserAbort`] error. /// [`DownloadError::UserAbort`] error.
#[instrument(skip(visitor, cancellation_future))]
pub async fn and_visit_tar<V: TarEntriesVisitor + Debug + Send + 'static>( pub async fn and_visit_tar<V: TarEntriesVisitor + Debug + Send + 'static>(
self, self,
fmt: TarBasedFmt, fmt: TarBasedFmt,
@ -114,6 +115,7 @@ impl Download {
/// ///
/// `cancellation_future` can be used to cancel the extraction and return /// `cancellation_future` can be used to cancel the extraction and return
/// [`DownloadError::UserAbort`] error. /// [`DownloadError::UserAbort`] error.
#[instrument(skip(path, cancellation_future))]
pub async fn and_extract( pub async fn and_extract(
self, self,
fmt: PkgFmt, fmt: PkgFmt,

View file

@ -7,11 +7,11 @@ use std::{
use bytes::Bytes; use bytes::Bytes;
use futures_util::stream::Stream; use futures_util::stream::Stream;
use log::debug;
use scopeguard::{guard, ScopeGuard}; use scopeguard::{guard, ScopeGuard};
use tar::Entries; use tar::Entries;
use tempfile::tempfile; use tempfile::tempfile;
use tokio::task::block_in_place; use tokio::task::block_in_place;
use tracing::debug;
use super::{ use super::{
extracter::*, stream_readable::StreamReadable, CancellationFuture, DownloadError, TarBasedFmt, extracter::*, stream_readable::StreamReadable, CancellationFuture, DownloadError, TarBasedFmt,

View file

@ -6,8 +6,8 @@ use std::{
use bzip2::bufread::BzDecoder; use bzip2::bufread::BzDecoder;
use flate2::bufread::GzDecoder; use flate2::bufread::GzDecoder;
use log::debug;
use tar::Archive; use tar::Archive;
use tracing::debug;
use xz2::bufread::XzDecoder; use xz2::bufread::XzDecoder;
use zip::read::ZipArchive; use zip::read::ZipArchive;
use zstd::stream::Decoder as ZstdDecoder; use zstd::stream::Decoder as ZstdDecoder;

View file

@ -8,7 +8,6 @@ use std::{
use bytes::Bytes; use bytes::Bytes;
use futures_util::stream::{Stream, StreamExt}; use futures_util::stream::{Stream, StreamExt};
use httpdate::parse_http_date; use httpdate::parse_http_date;
use log::{debug, info};
use reqwest::{ use reqwest::{
header::{HeaderMap, RETRY_AFTER}, header::{HeaderMap, RETRY_AFTER},
Request, Response, StatusCode, Request, Response, StatusCode,
@ -16,6 +15,7 @@ use reqwest::{
use thiserror::Error as ThisError; use thiserror::Error as ThisError;
use tokio::{sync::Mutex, time::sleep}; use tokio::{sync::Mutex, time::sleep};
use tower::{limit::rate::RateLimit, Service, ServiceBuilder, ServiceExt}; use tower::{limit::rate::RateLimit, Service, ServiceBuilder, ServiceExt};
use tracing::{debug, info};
pub use reqwest::{tls, Error as ReqwestError, Method}; pub use reqwest::{tls, Error as ReqwestError, Method};
pub use url::Url; pub use url::Url;

View file

@ -21,7 +21,6 @@ futures-util = { version = "0.3.25", default-features = false, features = ["std"
home = "0.5.4" home = "0.5.4"
itertools = "0.10.5" itertools = "0.10.5"
jobslot = { version = "0.2.6", features = ["tokio"] } jobslot = { version = "0.2.6", features = ["tokio"] }
log = { version = "0.4.17", features = ["std"] }
miette = "5.4.1" miette = "5.4.1"
normalize-path = { version = "0.2.0", path = "../normalize-path" } normalize-path = { version = "0.2.0", path = "../normalize-path" }
once_cell = "1.16.0" once_cell = "1.16.0"
@ -33,12 +32,10 @@ thiserror = "1.0.37"
tinytemplate = "1.2.1" tinytemplate = "1.2.1"
# parking_lot for `tokio::sync::OnceCell::const_new` # parking_lot for `tokio::sync::OnceCell::const_new`
tokio = { version = "1.21.2", features = ["rt", "process", "sync", "signal", "parking_lot"], default-features = false } 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"] } url = { version = "2.3.1", features = ["serde"] }
xz2 = "0.1.7" xz2 = "0.1.7"
[dev-dependencies]
env_logger = "0.9.3"
[features] [features]
default = ["static", "rustls"] default = ["static", "rustls"]

View file

@ -6,10 +6,10 @@ use std::{
use cargo_toml::Product; use cargo_toml::Product;
use compact_str::CompactString; use compact_str::CompactString;
use log::debug;
use normalize_path::NormalizePath; use normalize_path::NormalizePath;
use serde::Serialize; use serde::Serialize;
use tinytemplate::TinyTemplate; use tinytemplate::TinyTemplate;
use tracing::debug;
use crate::{ use crate::{
errors::BinstallError, errors::BinstallError,

View file

@ -2,8 +2,8 @@ use std::path::PathBuf;
use cargo_toml::Manifest; use cargo_toml::Manifest;
use crates_io_api::AsyncClient; use crates_io_api::AsyncClient;
use log::debug;
use semver::VersionReq; use semver::VersionReq;
use tracing::debug;
use crate::{ use crate::{
errors::BinstallError, errors::BinstallError,

View file

@ -4,8 +4,8 @@ use std::{
}; };
use cargo_toml::Manifest; use cargo_toml::Manifest;
use log::debug;
use normalize_path::NormalizePath; use normalize_path::NormalizePath;
use tracing::debug;
use super::vfs::Vfs; use super::vfs::Vfs;
use crate::{ use crate::{

View file

@ -1,5 +1,5 @@
use log::debug;
use semver::VersionReq; use semver::VersionReq;
use tracing::debug;
use crate::errors::BinstallError; use crate::errors::BinstallError;

View file

@ -2,7 +2,6 @@ use std::{path::Path, sync::Arc};
use compact_str::CompactString; use compact_str::CompactString;
pub use gh_crate_meta::*; pub use gh_crate_meta::*;
pub use log::debug;
pub use quickinstall::*; pub use quickinstall::*;
use crate::{ use crate::{

View file

@ -2,11 +2,11 @@ use std::{path::Path, sync::Arc};
use compact_str::{CompactString, ToCompactString}; use compact_str::{CompactString, ToCompactString};
use futures_util::stream::{FuturesUnordered, StreamExt}; use futures_util::stream::{FuturesUnordered, StreamExt};
use log::{debug, warn};
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use serde::Serialize; use serde::Serialize;
use strum::IntoEnumIterator; use strum::IntoEnumIterator;
use tinytemplate::TinyTemplate; use tinytemplate::TinyTemplate;
use tracing::{debug, warn};
use url::Url; use url::Url;
use crate::{ use crate::{

View file

@ -1,8 +1,8 @@
use std::{path::Path, sync::Arc}; use std::{path::Path, sync::Arc};
use compact_str::CompactString; use compact_str::CompactString;
use log::debug;
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
use tracing::debug;
use url::Url; use url::Url;
use crate::{ use crate::{

View file

@ -1,7 +1,7 @@
use std::{fs, io, path::Path}; use std::{fs, io, path::Path};
use log::debug;
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
use tracing::debug;
/// Atomically install a file. /// Atomically install a file.
/// ///

View file

@ -1,8 +1,8 @@
use std::{borrow::Cow, env, ffi::OsStr, sync::Arc}; use std::{borrow::Cow, env, ffi::OsStr, sync::Arc};
use compact_str::CompactString; use compact_str::CompactString;
use log::{debug, error, info};
use tokio::{process::Command, task::block_in_place}; use tokio::{process::Command, task::block_in_place};
use tracing::{debug, error, info, instrument};
use super::{resolve::Resolution, Options}; use super::{resolve::Resolution, Options};
use crate::{ use crate::{
@ -12,6 +12,7 @@ use crate::{
manifests::crate_info::{CrateInfo, CrateSource}, manifests::crate_info::{CrateInfo, CrateSource},
}; };
#[instrument(skip_all)]
pub async fn install( pub async fn install(
resolution: Resolution, resolution: Resolution,
opts: Arc<Options>, opts: Arc<Options>,

View file

@ -9,9 +9,9 @@ use std::{
use cargo_toml::{Manifest, Package, Product}; use cargo_toml::{Manifest, Package, Product};
use compact_str::{CompactString, ToCompactString}; use compact_str::{CompactString, ToCompactString};
use itertools::Itertools; use itertools::Itertools;
use log::{debug, info, warn};
use semver::{Version, VersionReq}; use semver::{Version, VersionReq};
use tokio::task::block_in_place; use tokio::task::block_in_place;
use tracing::{debug, info, instrument, warn};
use super::Options; use super::Options;
use crate::{ use crate::{
@ -89,6 +89,7 @@ impl Resolution {
} }
} }
#[instrument(skip_all)]
pub async fn resolve( pub async fn resolve(
opts: Arc<Options>, opts: Arc<Options>,
crate_name: CrateName, crate_name: CrateName,

View file

@ -3,8 +3,6 @@ use cargo_toml::Product;
#[test] #[test]
fn parse_meta() { fn parse_meta() {
let _ = env_logger::builder().is_test(true).try_init();
let mut manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); let mut manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
manifest_dir.push_str("/tests/parse-meta.Cargo.toml"); manifest_dir.push_str("/tests/parse-meta.Cargo.toml");