From 19d326917cf5a7010e7c5ece1051a01caf01bc87 Mon Sep 17 00:00:00 2001 From: holly sparkles Date: Sun, 21 Jan 2024 09:02:11 +0100 Subject: [PATCH] feat: add logging --- Cargo.lock | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/main.rs | 12 ++++++++++-- 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 674e3d3..401b826 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,6 +18,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] name = "anstream" version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -160,6 +169,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eeb342678d785662fd2514be38c459bb925f02b68dd2a3e0f21d7ef82d979dd" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + +[[package]] name = "gimli" version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -170,7 +202,9 @@ name = "git-mirror-sync" version = "0.1.0" dependencies = [ "clap", + "env_logger", "humantime", + "log", "serde", "tokio", "walkdir", @@ -211,6 +245,12 @@ dependencies = [ ] [[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] name = "memchr" version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -312,6 +352,35 @@ dependencies = [ ] [[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] name = "rustc-demangle" version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml index 773ab76..a1c7f9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,9 @@ edition = "2021" [dependencies] clap = { version = "4.4.18", features = ["derive"] } +env_logger = "0.11.0" humantime = "2.1.0" +log = "0.4.20" serde = { version = "1.0.195", features = ["derive"] } tokio = { version = "1.35.1", features = ["full"] } walkdir = "2.4.0" diff --git a/src/main.rs b/src/main.rs index 201e439..75d3e0a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,8 @@ +use std::env; + use clap::Parser; use cli::CliArgs; +use log::{error, info}; use tokio::{process::Command, time::sleep}; use walkdir::WalkDir; @@ -8,12 +11,17 @@ mod error; #[tokio::main] async fn main() { + env::set_var("RUST_LOG", "info"); + env_logger::init(); + loop { do_sync_task(CliArgs::parse()).await } } async fn do_sync_task(args: CliArgs) { + info!("Performing sync task."); + for dir in WalkDir::new(args.directory) .max_depth(3) .into_iter() @@ -42,11 +50,11 @@ async fn do_sync_task(args: CliArgs) { .await .expect("Unable to fetch repository"); if !status.success() { - println!("Succes") + error!("Failed to update repository {:?}", dir.path()) } } } - println!("Sleeping until the next refresh."); + info!("Sleeping until the next refresh."); sleep(args.refresh_time.into()).await; } -- libgit2 1.7.2