Skip to content

Commit

Permalink
use tracing (#30)
Browse files Browse the repository at this point in the history
Signed-off-by: Ankur Srivastava <[email protected]>
  • Loading branch information
ansrivas authored Jan 11, 2021
1 parent b2e0c30 commit 587cb16
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 26 deletions.
20 changes: 9 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ include = [
[dependencies]
openssl = { version = "0.10", features = ["vendored"], optional = true }

env_logger = "0.8"
log = "0.4"
tracing = "0.1"

percent-encoding = "2.1.0"

serde_derive = "1.0"
Expand All @@ -30,28 +30,26 @@ serde_json = "1.0"
thiserror = "1.0"
url = "2.1"
bytes= "1.0"
once_cell= "1.5"
mockito = "0.28.0"

serde_bytes = "0.11"

once_cell= {version = "1.5"}
mockito = {version = "0.28"}
tracing-subscriber = {version = "0.2"}

[dependencies.reqwest]
features = ["json"]
version = "0.11"

[dev-dependencies.smol]
version = "1.2.5"

[dev-dependencies.tokio]
features = ["full"]
version = "1"

[dev-dependencies]
anyhow = "1.0"
async-compat = "0.1.3"
tokio = {version="1", features = ["full"]}
smol = "1.2.5"

[features]
static=["openssl"]


[lib]
name = "aiven_rs"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ async fn main() {
}
}
```
## Running the examples:
```sh
RUST_LOG=aiven_rs=debug cargo run --example clouds
```
## License

This project is licensed under
Expand Down
2 changes: 1 addition & 1 deletion examples/clouds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use aiven_rs::{cloud::types::ResClouds, AivenClient};

#[tokio::main]
async fn main() {
env_logger::init();
tracing_subscriber::fmt::init();

// use std::env;
// let token = env::var("AIVEN_TOKEN").expect("Please set env variable to read
Expand Down
2 changes: 1 addition & 1 deletion examples/clouds_smol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use smol;

fn main() -> Result<()> {
smol::block_on(Compat::new(async {
env_logger::init();
tracing_subscriber::fmt::init();

let client = AivenClient::new("https://api.aiven.io", "v1");
let cloud_api = client.cloud();
Expand Down
2 changes: 1 addition & 1 deletion examples/list_service_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::env;

fn main() -> Result<()> {
smol::block_on(Compat::new(async {
env_logger::init();
tracing_subscriber::fmt::init();

let token = env::var("AIVEN_TOKEN").expect("Please set env variable to read AIVEN_TOKEN");
let client = AivenClient::from_token("https://api.aiven.io", "v1", &token);
Expand Down
4 changes: 2 additions & 2 deletions examples/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
// SOFTWARE.

use aiven_rs::AivenClient;
use log::info;
use tracing::info;
use std::{collections::HashMap, env};

#[tokio::main]
async fn main() {
env_logger::init();
tracing_subscriber::fmt::init();
let token = env::var("AIVEN_TOKEN").expect("Please set env variable to read AIVEN_TOKEN");
let client = AivenClient::from_token("https://api.aiven.io", "v1", &token);
let cloud = client.project();
Expand Down
4 changes: 2 additions & 2 deletions examples/user_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
// SOFTWARE.

use aiven_rs;
use log::info;
use tracing::info;
use std::collections::HashMap;

#[tokio::main]
async fn main() {
env_logger::init();
tracing_subscriber::fmt::init();
let client = aiven_rs::AivenClient::new("https://api.aiven.io", "v1");
let mut json_body = HashMap::new();
json_body.insert("email", "someemail".to_owned());
Expand Down
15 changes: 8 additions & 7 deletions src/client/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
// SOFTWARE.

use crate::errors::AivenError;
use log::debug;
// use log::debug;
use percent_encoding::{percent_encode, NON_ALPHANUMERIC};
use serde::{Deserialize, Serialize};
use tracing::debug;

#[derive(Debug, Clone)]
pub struct HTTPClient {
Expand Down Expand Up @@ -54,8 +55,8 @@ pub(crate) fn encode_param(param: &str) -> String {
macro_rules! make_json_request {
($sel:ident, $method:path, $url:expr, $body:ident) => {{
use crate::{client::APIResponse, errors::AivenError};
use log::debug;
use reqwest;
use tracing::error;

let response: reqwest::Response = $sel
.http_client
Expand All @@ -66,8 +67,8 @@ macro_rules! make_json_request {
let status_code = &response.status().as_u16();

if !(*status_code >= 200 && *status_code < 300) {
debug!("status_code = {}", status_code);
debug!("url queried = {}", $url);
error!("status_code = {}", status_code);
error!("url queried = {}", $url);
let api_response: APIResponse = response.json().await?;
return Err(AivenError::APIResponseError {
errors: api_response.errors.unwrap(),
Expand All @@ -83,13 +84,13 @@ macro_rules! make_json_request {
#[macro_export]
macro_rules! make_request {
($sel:ident, $method:path, $url:expr) => {{
use log::debug;
use tracing::debug;
use reqwest;
let response: reqwest::Response = $sel.http_client.inner($method, $url)?.send().await?;
use crate::client::APIResponse;

let status_code = &response.status().as_u16();
debug!("Received status code: {}", status_code);
debug!("Received http status code: {}", status_code);

if !(*status_code >= 200 && *status_code < 300) {
let api_response: APIResponse = response.json().await?;
Expand All @@ -112,7 +113,7 @@ impl HTTPClient {
reqwest::Url::parse(&base_url.into()).expect("Failed to parse the base_url");

let ver = format!("{}/", version.replace("/", ""));
debug!("Version is {}", &ver);
debug!("API Version is {}", &ver);
HTTPClient {
base_url: parsed_url,
client,
Expand Down
2 changes: 1 addition & 1 deletion src/testutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static TEST_AIVEN_CLIENT: OnceCell<AivenClient> = OnceCell::new();
#[allow(dead_code)]
pub(crate) fn prepare_test_client() -> &'static AivenClient {
TEST_AIVEN_CLIENT.get_or_init(|| {
env_logger::init();
tracing_subscriber::fmt::init();
let url = &mockito::server_url();
println!("Test client not found, recreating {:?}", &url);
let token = env::var("AIVEN_TOKEN").unwrap_or_else(|_| "abc".to_string());
Expand Down

0 comments on commit 587cb16

Please sign in to comment.