diff options
author | Nick Gerace <nickagerace@gmail.com> | 2021-12-28 15:36:49 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-28 15:36:49 -0500 |
commit | bf4769a542028b3e92c1d58655fe5ae3a819468d (patch) | |
tree | 722658df3dc3f0927953f0bf3d00306db59b7ae3 | |
parent | 8ec790a157e5d76c664fa3c32d1b97490fa8cc32 (diff) | |
download | gfold-bf4769a542028b3e92c1d58655fe5ae3a819468d.zip |
Add debug logs for git executions (#159)
- Add debug logs for git executions with pre-info and post-info
- Declaratively set env logger rather than setting "RUST_LOG" from
within the program
Signed-off-by: Nick Gerace <nickagerace@gmail.com>
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | README.md | 7 | ||||
-rwxr-xr-x | scripts/uninstall.sh | 2 | ||||
-rw-r--r-- | src/logging.rs | 13 | ||||
-rw-r--r-- | src/report.rs | 9 |
5 files changed, 30 insertions, 10 deletions
@@ -34,6 +34,10 @@ clean: cd $(MAKEPATH); cargo clean .PHONY: clean +install: + cargo install --path $(MAKEPATH) +.PHONY: install + scan: cd $(MAKEPATH); cargo +nightly udeps cd $(MAKEPATH); cargo bloat --release @@ -47,6 +51,9 @@ bench-loosely: @echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" @time $(NEW) -i ~/ @echo "=============================================================" +.PHONY: bench-loosely + +compare: @du -h $(INSTALLED) @du -h $(NEW) -.PHONY: bench-loosely +.PHONY: compare @@ -104,13 +104,13 @@ cargo install-update -a If you do not want to use one of the above installation methods, you can download a binary from the [releases](https://github.com/nickgerace/gfold/releases) page. ```bash -curl https://raw.githubusercontent.com/nickgerace/gfold/main/scripts/install.sh | bash +curl -s https://raw.githubusercontent.com/nickgerace/gfold/main/scripts/install.sh | bash ``` To uninstall `gfold` fully, after using this installation method, execute the following script: ```bash -curl https://raw.githubusercontent.com/nickgerace/gfold/main/scripts/uninstall.sh | bash +curl -s https://raw.githubusercontent.com/nickgerace/gfold/main/scripts/uninstall.sh | bash ``` The uninstall script can also be used for cleanup in the event of a failed install. @@ -163,7 +163,8 @@ Here are the contents of the resulting config file: ```json { "path": "/home/neloth", - "display_mode": "Classic" + "display_mode": "Classic", + "git_path": null } ``` diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index 3064282..a9e7fc4 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -8,7 +8,7 @@ function perform-uninstall { echo "[uninstall-gfold] ✅ deleted $FILE" fi done - echo "[uninstall-gfold] ✅ gfold has been uninstalled from your system" + echo "[uninstall-gfold] ✅ uninstallation/cleanup has completed successfully" if [ -f $HOME/.config/gfold/gfold.json ]; then echo "[uninstall-gfold] ⚠️ you may want to delete or backup the config file" diff --git a/src/logging.rs b/src/logging.rs index 2c2f1b2..3c23ccf 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -1,10 +1,13 @@ +use env_logger::Builder; +use log::LevelFilter; use std::env; pub fn init(debug: bool) { - if debug { - env::set_var("RUST_LOG", "debug"); - } else if env::var("RUST_LOG").is_err() { - env::set_var("RUST_LOG", "off"); + match debug { + true => Builder::new().filter_level(LevelFilter::Debug).init(), + false => match env::var("RUST_LOG").is_err() { + true => Builder::new().filter_level(LevelFilter::Off).init(), + false => env_logger::init(), + }, } - env_logger::init(); } diff --git a/src/report.rs b/src/report.rs index 085a6b9..df09b3e 100644 --- a/src/report.rs +++ b/src/report.rs @@ -4,6 +4,7 @@ use crate::error::Error; use crate::status::Status; use crate::target_gen::Targets; use anyhow::Result; +use log::debug; use rayon::prelude::*; use std::collections::BTreeMap; use std::path::{Path, PathBuf}; @@ -89,6 +90,10 @@ fn generate_report(repo_path: &Path, git_path: &Path, include_email: bool) -> Re }; let status_as_string = format!("{:?}", &status).to_lowercase(); + debug!( + "generating report for repository at {:?} on branch {} with status: {:?}", + &repo_path, &branch, &status + ); Ok(Report { path: match repo_path.file_name() { Some(s) => match s.to_str() { @@ -178,6 +183,10 @@ impl GitShim { .args(args) .current_dir(&self.working_directory) .output()?; + debug!( + "executed {:?} in {:?} with args {:?}: {:?}", + &self.git_path, &self.working_directory, args, output + ); Ok(String::from_utf8(output.stdout)?) } } |