From 42be672206cbc3f755ead8c26f8642e81157af74 Mon Sep 17 00:00:00 2001 From: Heiko Seeberger Date: Fri, 13 Oct 2023 10:00:46 +0200 Subject: [PATCH] chore: cleanup logging related code (#19) --- examples/simple.rs | 6 +++--- examples/transform.rs | 12 ++++++------ src/publisher/mod.rs | 7 ++----- src/subscriber/mod.rs | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/examples/simple.rs b/examples/simple.rs index 8b10d87..6693e4f 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -39,7 +39,7 @@ async fn run() -> Result<(), Error> { .publish(TOPIC_ID, messages, None, None) .await?; let message_ids = message_ids.join(", "); - println!("Published messages with IDs: {message_ids}"); + println!("published messages with IDs: {message_ids}"); let pulled_messages = pub_sub_client .pull::(SUBSCRIPTION_ID, 42, None) @@ -47,14 +47,14 @@ async fn run() -> Result<(), Error> { for pulled_message in pulled_messages { match pulled_message.message { - Ok(m) => println!("Pulled message with text \"{}\"", m.text), + Ok(m) => println!("pulled message with text \"{}\"", m.text), Err(e) => eprintln!("ERROR: {e}"), } pub_sub_client .acknowledge(SUBSCRIPTION_ID, vec![&pulled_message.ack_id], None) .await?; - println!("Acknowledged message with ID {}", pulled_message.id); + println!("acknowledged message with ID {}", pulled_message.id); } Ok(()) diff --git a/examples/transform.rs b/examples/transform.rs index 52e3a8d..0eb74be 100644 --- a/examples/transform.rs +++ b/examples/transform.rs @@ -48,7 +48,7 @@ async fn run() -> Result<(), Error> { .collect::>(); let message_ids = pub_sub_client.publish_raw(TOPIC_ID, messages, None).await?; let message_ids = message_ids.join(", "); - println!("Published messages with IDs: {message_ids}"); + println!("published messages with IDs: {message_ids}"); let pulled_messages = pub_sub_client .pull_with_transform::( @@ -70,7 +70,7 @@ async fn run() -> Result<(), Error> { delivery_attempt, } = pulled_message; println!( - "Pulled message `{message:?}` with ID {id} and {delivery_attempt}. delivery attempt" + "pulled message `{message:?}` with ID {id} and {delivery_attempt}. delivery attempt" ); pub_sub_client @@ -80,7 +80,7 @@ async fn run() -> Result<(), Error> { Some(Duration::from_secs(10)), ) .await?; - println!("Successfully acknowledged message with ID {id}"); + println!("acknowledged message with ID {id}"); } Ok(()) @@ -98,11 +98,11 @@ fn transform( map.insert("type".to_string(), Value::String(t.to_string())); Ok(Value::Object(map)) } - other => Err(anyhow!("Unexpected JSON value `{other}`").into()), + other => Err(anyhow!("unexpected JSON value `{other}`").into()), }, None => { let e = anyhow!( - "Missing `type` attribute, message ID is `{}`", + "missing `type` attribute, message ID is `{}`", received_message.message.id ); Err(e.into()) @@ -110,7 +110,7 @@ fn transform( }, None => { let e = anyhow!( - "Missing attributes, message ID is `{}`", + "missing attributes, message ID is `{}`", received_message.message.id ); Err(e.into()) diff --git a/src/publisher/mod.rs b/src/publisher/mod.rs index f2c64b2..a7a8405 100644 --- a/src/publisher/mod.rs +++ b/src/publisher/mod.rs @@ -127,7 +127,7 @@ impl PubSubClient { ) -> Result, Error> { let url = self.topic_url(topic_id); let request = PublishRequest { messages }; - debug!(message = "Sending request", url = display(&url)); + debug!(url, "sending request"); let response = self.send_request(&url, &request, timeout).await?; if !response.status().is_success() { @@ -139,10 +139,7 @@ impl PubSubClient { .await .map_err(Error::UnexpectedHttpResponse)? .message_ids; - debug!( - message = "Request was successful", - message_ids = debug(&message_ids) - ); + debug!(?message_ids, "successfully published"); Ok(message_ids) } diff --git a/src/subscriber/mod.rs b/src/subscriber/mod.rs index 6701732..633ffa7 100644 --- a/src/subscriber/mod.rs +++ b/src/subscriber/mod.rs @@ -106,7 +106,7 @@ impl PubSubClient { ) -> Result, Error> { let url = self.subscription_url(subscription_id, "pull"); let request = PullRequest { max_messages }; - debug!(message = "Sending request", url = display(&url)); + debug!(url, "sending request"); let response = self.send_request(&url, &request, timeout).await?; if !response.status().is_success() {