add logging

This commit is contained in:
LordMZTE 2020-12-06 14:57:14 +01:00
parent 03d2e5f5b1
commit 83cb590727
5 changed files with 18 additions and 4 deletions

View file

@ -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"] }

View file

@ -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));
}
}

View file

@ -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()

View file

@ -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();

View file

@ -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<String>> {
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<String>> {
pub async fn memes(http: &Client) -> Result<&Vec<Meme>> {
if MEMES.get().is_none() {
info!("Requesting memes from server");
let res = http
.get("https://data.tilera.xyz/api/jensmemes/memes")
.send()