From 83cb5907279597c687281f6afef9b3d2a253d34c Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Sun, 6 Dec 2020 14:57:14 +0100 Subject: [PATCH] add logging --- cli/Cargo.toml | 2 ++ cli/src/commands/search.rs | 6 +++++- cli/src/commands/up.rs | 8 ++++++-- cli/src/main.rs | 2 ++ cli/src/util.rs | 4 +++- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 1c80674..4af581b 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -13,7 +13,9 @@ path = "src/main.rs" [dependencies] anyhow = "1.0.34" clap = "2.33.3" +env_logger = "0.8.2" fuzzy-matcher = "0.3.7" +log = "0.4.11" once_cell = "1.5.2" opener = "0.4.1" reqwest = { version = "0.10.9", features = ["stream"] } diff --git a/cli/src/commands/search.rs b/cli/src/commands/search.rs index a6af255..84f042d 100644 --- a/cli/src/commands/search.rs +++ b/cli/src/commands/search.rs @@ -1,4 +1,5 @@ use anyhow::Result; +use log::info; use reqwest::Client; use crate::util; @@ -8,8 +9,11 @@ pub async fn run(http: &Client, query: String) -> Result<()> { let mut matches = vec![]; + info!("Starting search with query '{}'", query); for meme in memes { - if let Some(score) = fuzzy_matcher::clangd::fuzzy_match(meme.file_name()?, &query) { + let file_name = meme.file_name()?; + if let Some(score) = fuzzy_matcher::clangd::fuzzy_match(file_name, &query) { + info!("Found matching meme '{}' with score {}", file_name, score); matches.push((meme, score)); } } diff --git a/cli/src/commands/up.rs b/cli/src/commands/up.rs index 1ae1c4c..ea3ad58 100644 --- a/cli/src/commands/up.rs +++ b/cli/src/commands/up.rs @@ -1,4 +1,5 @@ use anyhow::{bail, Result}; +use log::info; use reqwest::{ multipart::{Form, Part}, Body, @@ -31,8 +32,11 @@ pub async fn run( .text("token", token) .part( "file", - Part::stream(Body::wrap_stream(reader_stream(File::open(path).await?))) - .file_name(name), + Part::stream(Body::wrap_stream(reader_stream({ + info!("Opening file {}", &path); + File::open(path).await? + }))) + .file_name(name), ), ) .send() diff --git a/cli/src/main.rs b/cli/src/main.rs index 0ad5307..2f8324c 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -51,6 +51,8 @@ enum Cmd { #[tokio::main] async fn main() -> Result<()> { + env_logger::init(); + let Opts { cmd } = Opts::from_args(); let http = Client::new(); diff --git a/cli/src/util.rs b/cli/src/util.rs index 0c4cf71..4182c45 100644 --- a/cli/src/util.rs +++ b/cli/src/util.rs @@ -1,7 +1,7 @@ - use std::unreachable; use anyhow::Result; +use log::info; use once_cell::sync::OnceCell; use reqwest::Client; use term_table::{Table, TableBuilder, TableStyle}; @@ -26,6 +26,7 @@ pub async fn open_link(url: &str) -> anyhow::Result<()> { pub async fn cats(http: &Client) -> Result<&Vec> { if CATS.get().is_none() { + info!("Requesting categories from server"); let res = http .get("https://data.tilera.xyz/api/jensmemes/categories") .send() @@ -40,6 +41,7 @@ pub async fn cats(http: &Client) -> Result<&Vec> { pub async fn memes(http: &Client) -> Result<&Vec> { if MEMES.get().is_none() { + info!("Requesting memes from server"); let res = http .get("https://data.tilera.xyz/api/jensmemes/memes") .send()