From ba2146ff7d0b003fec227c04b20be348a2657f0a Mon Sep 17 00:00:00 2001 From: Shoaib Ahmed Date: Sun, 26 May 2024 12:56:52 -0700 Subject: [PATCH] cycles-sync: Fix logging (#5) --- utils/cycles-sync/src/main.rs | 11 ++++++----- utils/cycles-sync/src/obligato_client/http.rs | 3 ++- utils/cycles-sync/src/wasmd_client.rs | 10 ++++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/utils/cycles-sync/src/main.rs b/utils/cycles-sync/src/main.rs index f15b56f..f33fb8d 100644 --- a/utils/cycles-sync/src/main.rs +++ b/utils/cycles-sync/src/main.rs @@ -18,7 +18,7 @@ use clap::Parser; use cosmwasm_std::HexBinary; use serde::{Deserialize, Serialize}; use serde_json::json; -use tracing::{info, Level}; +use tracing::{debug, Level}; use uuid::Uuid; use crate::{ @@ -60,9 +60,10 @@ async fn main() -> Result<(), DynError> { .with_max_level(if cli.verbose { Level::DEBUG } else { - Level::INFO + Level::ERROR }) .with_level(true) + .with_writer(std::io::stderr) .init(); match cli.command { @@ -115,7 +116,7 @@ async fn sync_setoffs(cli: Cli) -> Result<(), DynError> { }) .collect(); - info!("setoffs: {setoffs:?}"); + debug!("setoffs: {setoffs:?}"); // send to Obligato let client = HttpClient::new(OBLIGATO_URL.parse().unwrap()); @@ -136,13 +137,13 @@ async fn sync_obligations(cli: Cli, epoch_pk: &str) -> Result<(), DynError> { add_default_acceptances(&mut intents, bank_id); - info!("intents: {intents:?}"); + debug!("intents: {intents:?}"); let intents_enc = { let epoch_pk = VerifyingKey::from_sec1_bytes(&hex::decode(epoch_pk).unwrap()).unwrap(); encrypt_intents(intents, keys, &epoch_pk, cli.obligation_user_map_file) }; - info!("Encrypted {} intents", intents_enc.len()); + debug!("Encrypted {} intents", intents_enc.len()); let msg = create_wasm_msg(intents_enc); let wasmd_client = CliWasmdClient::new(cli.node); diff --git a/utils/cycles-sync/src/obligato_client/http.rs b/utils/cycles-sync/src/obligato_client/http.rs index 03e1c49..b44b9b2 100644 --- a/utils/cycles-sync/src/obligato_client/http.rs +++ b/utils/cycles-sync/src/obligato_client/http.rs @@ -2,6 +2,7 @@ use async_trait::async_trait; use reqwest::Url; use serde::{Deserialize, Serialize}; use serde_json::json; +use tracing::log::debug; use crate::{ obligato_client::Client, @@ -54,7 +55,7 @@ impl Client for HttpClient { .json(&setoffs) .send() .await?; - println!("{}", response.text().await.unwrap()); + debug!("{}", response.text().await.unwrap()); Ok(()) } diff --git a/utils/cycles-sync/src/wasmd_client.rs b/utils/cycles-sync/src/wasmd_client.rs index 64196a5..b6836f8 100644 --- a/utils/cycles-sync/src/wasmd_client.rs +++ b/utils/cycles-sync/src/wasmd_client.rs @@ -3,6 +3,7 @@ use std::{error::Error, process::Command}; use cosmrs::{tendermint::chain::Id, AccountId}; use reqwest::Url; use serde::{Deserialize, Serialize}; +use tracing::debug; pub trait WasmdClient { type Address: AsRef; @@ -75,7 +76,7 @@ impl WasmdClient for CliWasmdClient { .args(["--output", "json"]); let output = command.output()?; - println!("{:?} => {:?}", command, output); + debug!("{:?} => {:?}", command, output); let query_result = R::from_vec(output.stdout); Ok(query_result) @@ -97,10 +98,15 @@ impl WasmdClient for CliWasmdClient { .args(["--chain-id", chain_id.as_ref()]) .args(["--gas", &gas.to_string()]) .args(["--from", sender.as_ref()]) + .args(["--output", "json"]) .arg("-y"); let output = command.output()?; - println!("{:?} => {:?}", command, output); + debug!("{:?} => {:?}", command, output); + + if output.status.success() { + println!("{}", String::from_utf8(output.stdout).unwrap()); + } Ok(()) }