From fa13e57835e487d586024a2e065e8f4b30dc88cd Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Fri, 2 Oct 2020 18:36:57 -0400 Subject: incorporate tracing instead of log (#222) * incorporate tracing instead of log * fix a test * fix a test --- lib/patreon/Cargo.toml | 3 ++- lib/patreon/src/lib.rs | 17 +++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/patreon/Cargo.toml b/lib/patreon/Cargo.toml index 47298b5..fc204a4 100644 --- a/lib/patreon/Cargo.toml +++ b/lib/patreon/Cargo.toml @@ -12,7 +12,8 @@ reqwest = { version = "0.10", features = ["json"] } serde_json = "1.0" serde = { version = "1", features = ["derive"] } thiserror = "1" -log = "0" +tracing = "0.1" +tracing-futures = "0.2" [dev-dependencies] tokio = { version = "0.2", features = ["macros"] } diff --git a/lib/patreon/src/lib.rs b/lib/patreon/src/lib.rs index 57e2c02..5e37ad7 100644 --- a/lib/patreon/src/lib.rs +++ b/lib/patreon/src/lib.rs @@ -1,6 +1,7 @@ +use chrono::prelude::*; use serde::{Deserialize, Serialize}; use thiserror::Error; -use chrono::prelude::*; +use tracing::{debug, error, instrument}; pub type Campaigns = Vec>; pub type Pledges = Vec>; @@ -70,7 +71,7 @@ pub enum Error { Request(#[from] reqwest::Error), } -#[derive(Debug, Serialize, Deserialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone, Default)] pub struct Credentials { pub client_id: String, pub client_secret: String, @@ -112,6 +113,7 @@ impl Client { } } + #[instrument(skip(self))] pub async fn campaign(&self) -> Result>, ()>> { let data = self .cli @@ -126,11 +128,14 @@ impl Client { ) .send() .await? - .error_for_status()?.text().await?; - log::debug!("campaign response: {}", data); + .error_for_status()? + .text() + .await?; + debug!("campaign response: {}", data); Ok(serde_json::from_str(&data)?) } + #[instrument(skip(self))] pub async fn pledges(&self, camp_id: String) -> Result>> { let data = self .cli @@ -148,8 +153,8 @@ impl Client { .error_for_status()? .text() .await?; - log::debug!("pledges for {}: {}", camp_id, data); - let data : Data>, Object> = serde_json::from_str(&data)?; + debug!("pledges for {}: {}", camp_id, data); + let data: Data>, Object> = serde_json::from_str(&data)?; Ok(data.included.unwrap()) } } -- cgit v1.2.3