Skip to content

Commit

Permalink
refactor(libscoop): tweak tracing output
Browse files Browse the repository at this point in the history
Signed-off-by: Chawye Hsu <[email protected]>
  • Loading branch information
chawyehsu committed Dec 10, 2024
1 parent d835c7f commit 95c8937
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 21 deletions.
10 changes: 7 additions & 3 deletions crates/libscoop/src/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use once_cell::sync::OnceCell;
use rayon::prelude::{IntoParallelIterator, ParallelBridge, ParallelIterator};
use std::fs::DirEntry;
use std::path::{Path, PathBuf};
use tracing::debug;
use tracing::{debug, warn};

use crate::error::{Error, Fallible};
use crate::internal;
Expand Down Expand Up @@ -218,7 +218,7 @@ pub fn bucket_added(session: &Session) -> Fallible<Vec<Bucket>> {

match buckets_dir.read_dir() {
Err(err) => {
debug!("failed to read buckets dir ({})", err);
warn!("failed to read buckets dir (err: {})", err);
}
Ok(entries) => {
buckets = entries
Expand All @@ -231,7 +231,11 @@ pub fn bucket_added(session: &Session) -> Fallible<Vec<Bucket>> {
if is_dir {
match Bucket::from(&path) {
Err(err) => {
debug!("failed to parse bucket {} ({})", path.display(), err)
warn!(
"failed to parse bucket {} (err: {})",
path.display(),
err
)
}
Ok(bucket) => return Some(bucket),
}
Expand Down
4 changes: 0 additions & 4 deletions crates/libscoop/src/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ pub fn compare_versions<S: AsRef<str>>(ver_a: S, ver_b: S) -> std::cmp::Ordering
let ver_b = ver_b.as_ref();
let ver_a_parsed = ver_a.split(&['.', '-'][..]);
let mut ver_b_parsed = ver_b.split(&['.', '-'][..]);
// debug!(
// "ver_a_parsed: {:?}, ver_b_parsed: {:?}",
// ver_a_parsed, ver_b_parsed
// );

for a_part in ver_a_parsed {
match ver_b_parsed.next() {
Expand Down
6 changes: 3 additions & 3 deletions crates/libscoop/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::{
iter::FromIterator,
sync::{Arc, Mutex},
};
use tracing::debug;
use tracing::{debug, info};

use crate::{
bucket::{Bucket, BucketUpdateProgressContext},
Expand Down Expand Up @@ -129,7 +129,7 @@ pub fn bucket_update(session: &Session) -> Fallible<()> {

// There is no remote url for this bucket, so we just ignore it.
if bucket.remote_url().is_none() {
debug!("ignored not updatable bucket {}", bucket.name());
info!("ignored non-updatable bucket '{}'", bucket.name());
continue;
}

Expand Down Expand Up @@ -216,7 +216,7 @@ pub fn cache_list(session: &Session, query: &str) -> Fallible<Vec<CacheFile>> {

match cache_dir.read_dir() {
Err(err) => {
debug!("failed to read cache dir ({})", err);
debug!("failed to read cache dir (err: {})", err);
}
Ok(entires) => {
files = entires
Expand Down
15 changes: 11 additions & 4 deletions crates/libscoop/src/package/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fs::File;
use std::io::Read;
use std::marker::PhantomData;
use std::path::{Path, PathBuf};
use tracing::debug;
use tracing::{debug, warn};

use crate::constant::{REGEX_HASH, SPDX_LIST};
use crate::error::Fallible;
Expand Down Expand Up @@ -762,7 +762,7 @@ impl Manifest {
// `serde_json` which can parse JSON files much *faster*. Perhaps
// `simd_json` can be the one. See https://github.com/serde-rs/json-benchmark
let inner: ManifestSpec = serde_json::from_slice(&bytes).inspect_err(|e| {
debug!("failed to parse manifest {}", path.display());
warn!("failed to parse manifest {} (err: {})", path.display(), e);
})?;
let path = internal::path::normalize_path(path);
// let mut checksum = scoop_hash::Checksum::new("sha256");
Expand Down Expand Up @@ -1024,7 +1024,10 @@ impl Manifest {
for def in shim_defs {
match def.len() {
0 => {
debug!("invalid shim definition: {:?}", def);
warn!(
"invalid shim definition found in manifest {}",
self.path().display()
);
continue;
}
1 => shims.push(def[0]),
Expand Down Expand Up @@ -1239,7 +1242,11 @@ impl InstallInfo {
File::open(path)?.read_to_end(&mut bytes)?;

let info = serde_json::from_slice(&bytes).inspect_err(|e| {
debug!("failed to parse install_info {}", path.display());
warn!(
"failed to parse install_info {} (err: {})",
path.display(),
e
);
})?;

Ok(info)
Expand Down
6 changes: 3 additions & 3 deletions crates/libscoop/src/package/query.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rayon::prelude::{ParallelBridge, ParallelIterator};
use regex::{Regex, RegexBuilder};
use tracing::debug;
use tracing::{debug, info};

use crate::{
bucket::Bucket,
Expand Down Expand Up @@ -97,7 +97,7 @@ pub(crate) fn query_installed(
let mut ret = vec![];
match apps_dir.read_dir() {
Err(err) => {
debug!("failed to read apps dir ({})", err);
debug!("failed to read apps dir (err: {})", err);
}
Ok(entries) => {
ret = entries
Expand Down Expand Up @@ -209,7 +209,7 @@ pub(crate) fn query_installed(
// the upgradable option is requested.
if options.contains(&QueryOption::Upgradable) {
if bucket == ISOLATED_PACKAGE_BUCKET {
debug!("ignore isolated package '{}'", name);
info!("ignored isolated package '{}'", name);
// isolated packages are not upgradable currently,
// we may support it by live checking the origin
// manifest via the path/url in install_info.
Expand Down
4 changes: 2 additions & 2 deletions crates/libscoop/src/package/sync.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use once_cell::unsync::OnceCell;
use scoop_hash::ChecksumBuilder;
use std::io::Read;
use tracing::debug;
use tracing::{debug, info};

use crate::{
constant::REGEX_HASH, env, error::Fallible, internal, persist, psmodule, shim, shortcut, Error,
Expand Down Expand Up @@ -493,7 +493,7 @@ pub fn install(session: &Session, queries: &[&str], options: &[SyncOption]) -> F

for &pkg in packages.iter() {
if pkg.version() == "nightly" {
debug!("skip hash check for nightly package '{}'", pkg.name());
info!("skip hash check for nightly package '{}'", pkg.name());
continue;
}

Expand Down
5 changes: 3 additions & 2 deletions crates/libscoop/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use flume::{Receiver, Sender};
use once_cell::unsync::OnceCell;
use std::cell::{Ref, RefCell, RefMut};
use std::path::Path;
use tracing::debug;
use tracing::{debug, info, trace};

use crate::{
config::{possible_config_paths, Config, ConfigBuilder},
Expand Down Expand Up @@ -45,7 +45,8 @@ impl Session {
// load is done, return the session immediately.
for path in possible_config_paths() {
debug!("trying to load config from {}", path.display());
if let Ok(session) = Self::new_with(path) {
if let Ok(session) = Self::new_with(&path) {
info!("config loaded from {}", path.display());
return session;
}
}
Expand Down

0 comments on commit 95c8937

Please sign in to comment.