Skip to content

Commit

Permalink
Add logging support
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyr committed Sep 17, 2024
1 parent 7648d79 commit 4a46f54
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ ureq = "2.9.7"
font-types = { version = "0.7", features= ["serde"] }
thiserror = "1.0.37"
serde_yaml = "0.9.14"
log = "0.4"
env_logger = "0.11"
20 changes: 12 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn discover_sources(

let have_repo = pruned_candidates(&candidates);

eprintln!(
log::info!(
"checking {} repositories for config.yaml files",
have_repo.len()
);
Expand All @@ -116,13 +116,13 @@ pub fn discover_sources(
};

if verbose {
eprintln!(
log::debug!(
"{} of {} candidates have known repo url",
have_repo.len(),
candidates.len()
);

eprintln!(
log::debug!(
"{} of {} have sources/config.yaml",
has_config_files.len(),
have_repo.len()
Expand Down Expand Up @@ -295,7 +295,7 @@ fn find_config_files(
seen += 1;
}
Err(e) => {
eprintln!("channel error: '{e}'");
log::error!("channel error: '{e}'");
break;
}
}
Expand Down Expand Up @@ -366,7 +366,7 @@ fn config_file_from_remote_naive(repo_url: &str) -> Result<PathBuf, ConfigFetchI
Ok(resp) if resp.status() == 200 => return Ok(filename.into()),
Ok(resp) => {
// seems very unlikely but it feels bad to just skip this branch?
eprintln!("unexpected response code for {repo_url}: {}", resp.status());
log::warn!("unexpected response code for {repo_url}: {}", resp.status());
}
Err(ureq::Error::Status(404, _)) => (),
Err(ureq::Error::Status(429, resp)) => {
Expand Down Expand Up @@ -431,7 +431,7 @@ fn get_config_paths(font_dir: &Path) -> Option<Vec<PathBuf>> {
fn get_candidates_from_remote(verbose: bool) -> BTreeSet<Metadata> {
let tempdir = tempfile::tempdir().unwrap();
if verbose {
eprintln!("cloning {GF_REPO_URL} to {}", tempdir.path().display());
log::info!("cloning {GF_REPO_URL} to {}", tempdir.path().display());
}
clone_repo(GF_REPO_URL, tempdir.path())
.unwrap_or_die(|e| eprintln!("failed to checkout {GF_REPO_URL}: '{e}'"));
Expand All @@ -441,15 +441,15 @@ fn get_candidates_from_remote(verbose: bool) -> BTreeSet<Metadata> {
fn get_candidates_from_local_checkout(path: &Path, verbose: bool) -> BTreeSet<Metadata> {
let ofl_dir = path.join("ofl");
if verbose {
eprintln!("searching for candidates in {}", ofl_dir.display());
log::debug!("searching for candidates in {}", ofl_dir.display());
}
let mut result = BTreeSet::new();
for font_dir in iter_ofl_subdirectories(&ofl_dir) {
let metadata = match load_metadata(&font_dir) {
Ok(metadata) => metadata,
Err(e) => {
if verbose {
eprintln!("no metadata for font {}: '{}'", font_dir.display(), e);
log::warn!("no metadata for font {}: '{}'", font_dir.display(), e);
}
continue;
}
Expand Down Expand Up @@ -512,6 +512,10 @@ fn checkout_rev(repo_dir: &Path, rev: &str) -> Result<bool, GitFail> {
if left.starts_with(right) {
return Ok(true);
}
log::info!(
"repo {} needs fetch for {rev} (at {sha})",
repo_dir.display()
);
// checkouts might be shallow, so unshallow before looking for a rev:
let _ = std::process::Command::new("git")
.current_dir(repo_dir)
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use clap::Parser;
use google_fonts_sources::Args;

fn main() {
env_logger::init();
let args = Args::parse();
google_fonts_sources::run(&args);
}

0 comments on commit 4a46f54

Please sign in to comment.