From 376b9f474de7f94d45f5c27a87f1817fef3515ab Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 22 Jun 2023 12:10:23 -0700 Subject: [PATCH] use short syntax for json data in logs --- .../src/bin/web3_proxy_cli/change_admin_status.rs | 3 ++- .../src/bin/web3_proxy_cli/change_user_address.rs | 3 ++- web3_proxy/src/bin/web3_proxy_cli/change_user_tier.rs | 3 ++- .../bin/web3_proxy_cli/change_user_tier_by_address.rs | 5 +++-- .../src/bin/web3_proxy_cli/change_user_tier_by_key.rs | 5 +++-- .../src/bin/web3_proxy_cli/migrate_stats_to_v2.rs | 3 --- web3_proxy/src/bin/web3_proxy_cli/pagerduty.rs | 10 ++++------ web3_proxy/src/bin/web3_proxy_cli/sentryd/mod.rs | 5 +---- 8 files changed, 17 insertions(+), 20 deletions(-) diff --git a/web3_proxy/src/bin/web3_proxy_cli/change_admin_status.rs b/web3_proxy/src/bin/web3_proxy_cli/change_admin_status.rs index a6fcd9e5..cd0bd7b0 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/change_admin_status.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/change_admin_status.rs @@ -6,6 +6,7 @@ use log::{debug, info}; use migration::sea_orm::{ self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, ModelTrait, QueryFilter, }; +use serde_json::json; /// change a user's admin status. eiter they are an admin, or they aren't #[derive(FromArgs, PartialEq, Eq, Debug)] @@ -35,7 +36,7 @@ impl ChangeAdminStatusSubCommand { .await? .context(format!("No user with this id found {:?}", address))?; - debug!("user: {}", serde_json::to_string_pretty(&user)?); + debug!("user: {:#}", json!(&user)); // Check if there is a record in the database match admin::Entity::find() diff --git a/web3_proxy/src/bin/web3_proxy_cli/change_user_address.rs b/web3_proxy/src/bin/web3_proxy_cli/change_user_address.rs index 1dc41460..79eda477 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/change_user_address.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/change_user_address.rs @@ -7,6 +7,7 @@ use migration::sea_orm::{ self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter, }; +use serde_json::json; /// change a user's address. #[derive(FromArgs, PartialEq, Eq, Debug)] @@ -35,7 +36,7 @@ impl ChangeUserAddressSubCommand { .await? .context("No user found with that address")?; - debug!("initial user: {:#?}", u); + debug!("initial user: {:#}", json!(&u)); if u.address == new_address { info!("user already has this address"); diff --git a/web3_proxy/src/bin/web3_proxy_cli/change_user_tier.rs b/web3_proxy/src/bin/web3_proxy_cli/change_user_tier.rs index 2e672c80..a0cdea63 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/change_user_tier.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/change_user_tier.rs @@ -6,6 +6,7 @@ use migration::sea_orm::{ self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter, }; +use serde_json::json; /// change a user's tier. #[derive(FromArgs, PartialEq, Eq, Debug)] @@ -34,7 +35,7 @@ impl ChangeUserTierSubCommand { .await? .context("No user tier found with that name")?; - debug!("initial user_tier: {:#?}", user_tier); + debug!("initial user_tier: {:#}", json!(&user_tier)); let mut user_tier = user_tier.into_active_model(); diff --git a/web3_proxy/src/bin/web3_proxy_cli/change_user_tier_by_address.rs b/web3_proxy/src/bin/web3_proxy_cli/change_user_tier_by_address.rs index bd59d486..80c741fa 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/change_user_tier_by_address.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/change_user_tier_by_address.rs @@ -7,6 +7,7 @@ use migration::sea_orm::{ self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter, }; +use serde_json::json; /// change a user's tier. #[derive(FromArgs, PartialEq, Eq, Debug)] @@ -33,7 +34,7 @@ impl ChangeUserTierByAddressSubCommand { .context("No user found with that key")?; // TODO: don't serialize the rpc key - debug!("user: {:#?}", user); + debug!("user: {:#}", json!(&user)); // use the title to get the user tier let user_tier = user_tier::Entity::find() @@ -42,7 +43,7 @@ impl ChangeUserTierByAddressSubCommand { .await? .context("No user tier found with that name")?; - debug!("user_tier: {:#?}", user_tier); + debug!("user_tier: {:#}", json!(&user_tier)); if user.user_tier_id == user_tier.id { info!("user already has that tier"); diff --git a/web3_proxy/src/bin/web3_proxy_cli/change_user_tier_by_key.rs b/web3_proxy/src/bin/web3_proxy_cli/change_user_tier_by_key.rs index 1c0c05a0..a67100bb 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/change_user_tier_by_key.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/change_user_tier_by_key.rs @@ -6,6 +6,7 @@ use migration::sea_orm::{ self, ActiveModelTrait, ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter, }; +use serde_json::json; use uuid::Uuid; use web3_proxy::frontend::authorization::RpcSecretKey; @@ -34,7 +35,7 @@ impl ChangeUserTierByKeySubCommand { .await? .context("No user tier found with that name")?; - debug!("user_tier: {:#?}", user_tier); + debug!("user_tier: {:#}", json!(&user_tier)); // use the rpc secret key to get the user let user = user::Entity::find() @@ -44,7 +45,7 @@ impl ChangeUserTierByKeySubCommand { .await? .context("No user found with that key")?; - debug!("user: {:#?}", user); + debug!("user: {:#}", json!(&user)); if user.user_tier_id == user_tier.id { info!("user already has that tier"); diff --git a/web3_proxy/src/bin/web3_proxy_cli/migrate_stats_to_v2.rs b/web3_proxy/src/bin/web3_proxy_cli/migrate_stats_to_v2.rs index 0f3feadd..c1c11111 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/migrate_stats_to_v2.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/migrate_stats_to_v2.rs @@ -250,7 +250,6 @@ impl MigrateStatsToV2 { // Wait for any tasks that are on-going while let Some(x) = important_background_handles.next().await { - info!("Returned item is: {:?}", x); match x { Err(e) => { error!("{:?}", e); @@ -261,8 +260,6 @@ impl MigrateStatsToV2 { Ok(Ok(_)) => { // TODO: how can we know which handle exited? info!("a background handle exited"); - // Pop it in this case? - continue; } } } diff --git a/web3_proxy/src/bin/web3_proxy_cli/pagerduty.rs b/web3_proxy/src/bin/web3_proxy_cli/pagerduty.rs index 7e55103a..432578ab 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/pagerduty.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/pagerduty.rs @@ -1,6 +1,7 @@ use argh::FromArgs; use log::{error, info}; use pagerduty_rs::{eventsv2async::EventsV2 as PagerdutyAsyncEventsV2, types::Event}; +use serde_json::json; use web3_proxy::{ config::TopConfig, pagerduty::{pagerduty_alert, pagerduty_alert_for_config}, @@ -68,18 +69,15 @@ impl PagerdutySubCommand { }); if let Some(pagerduty_async) = pagerduty_async { - info!( - "sending to pagerduty: {}", - serde_json::to_string_pretty(&event)? - ); + info!("sending to pagerduty: {:#}", json!(&event)); if let Err(err) = pagerduty_async.event(Event::AlertTrigger(event)).await { error!("Failed sending to pagerduty: {}", err); } } else { info!( - "would send to pagerduty if PAGERDUTY_INTEGRATION_KEY were set: {}", - serde_json::to_string_pretty(&event)? + "would send to pagerduty if PAGERDUTY_INTEGRATION_KEY were set: {:#}", + json!(&event) ); } diff --git a/web3_proxy/src/bin/web3_proxy_cli/sentryd/mod.rs b/web3_proxy/src/bin/web3_proxy_cli/sentryd/mod.rs index 5e0af642..8d2e0888 100644 --- a/web3_proxy/src/bin/web3_proxy_cli/sentryd/mod.rs +++ b/web3_proxy/src/bin/web3_proxy_cli/sentryd/mod.rs @@ -142,10 +142,7 @@ impl SentrydSubCommand { ); if let Some(ref pagerduty_async) = pagerduty_async { - info!( - "sending to pagerduty: {:#}", - serde_json::to_string_pretty(&alert)? - ); + info!("sending to pagerduty: {:#}", json!(&alert)); if let Err(err) = pagerduty_async.event(Event::AlertTrigger(alert)).await