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] [dependencies]
anyhow = "1.0.34" anyhow = "1.0.34"
clap = "2.33.3" clap = "2.33.3"
env_logger = "0.8.2"
fuzzy-matcher = "0.3.7" fuzzy-matcher = "0.3.7"
log = "0.4.11"
once_cell = "1.5.2" once_cell = "1.5.2"
opener = "0.4.1" opener = "0.4.1"
reqwest = { version = "0.10.9", features = ["stream"] } reqwest = { version = "0.10.9", features = ["stream"] }

View file

@ -1,4 +1,5 @@
use anyhow::Result; use anyhow::Result;
use log::info;
use reqwest::Client; use reqwest::Client;
use crate::util; use crate::util;
@ -8,8 +9,11 @@ pub async fn run(http: &Client, query: String) -> Result<()> {
let mut matches = vec![]; let mut matches = vec![];
info!("Starting search with query '{}'", query);
for meme in memes { 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)); matches.push((meme, score));
} }
} }

View file

@ -1,4 +1,5 @@
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use log::info;
use reqwest::{ use reqwest::{
multipart::{Form, Part}, multipart::{Form, Part},
Body, Body,
@ -31,7 +32,10 @@ pub async fn run(
.text("token", token) .text("token", token)
.part( .part(
"file", "file",
Part::stream(Body::wrap_stream(reader_stream(File::open(path).await?))) Part::stream(Body::wrap_stream(reader_stream({
info!("Opening file {}", &path);
File::open(path).await?
})))
.file_name(name), .file_name(name),
), ),
) )

View file

@ -51,6 +51,8 @@ enum Cmd {
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
env_logger::init();
let Opts { cmd } = Opts::from_args(); let Opts { cmd } = Opts::from_args();
let http = Client::new(); let http = Client::new();

View file

@ -1,7 +1,7 @@
use std::unreachable; use std::unreachable;
use anyhow::Result; use anyhow::Result;
use log::info;
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use reqwest::Client; use reqwest::Client;
use term_table::{Table, TableBuilder, TableStyle}; 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>> { pub async fn cats(http: &Client) -> Result<&Vec<String>> {
if CATS.get().is_none() { if CATS.get().is_none() {
info!("Requesting categories from server");
let res = http let res = http
.get("https://data.tilera.xyz/api/jensmemes/categories") .get("https://data.tilera.xyz/api/jensmemes/categories")
.send() .send()
@ -40,6 +41,7 @@ pub async fn cats(http: &Client) -> Result<&Vec<String>> {
pub async fn memes(http: &Client) -> Result<&Vec<Meme>> { pub async fn memes(http: &Client) -> Result<&Vec<Meme>> {
if MEMES.get().is_none() { if MEMES.get().is_none() {
info!("Requesting memes from server");
let res = http let res = http
.get("https://data.tilera.xyz/api/jensmemes/memes") .get("https://data.tilera.xyz/api/jensmemes/memes")
.send() .send()