Skip to content

Commit

Permalink
chore: cleanup logging related code (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
hseeberger authored Oct 13, 2023
1 parent 5e70f96 commit 42be672
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
6 changes: 3 additions & 3 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ 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::<Message>(SUBSCRIPTION_ID, 42, None)
.await?;

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(())
Expand Down
12 changes: 6 additions & 6 deletions examples/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async fn run() -> Result<(), Error> {
.collect::<Vec<_>>();
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::<Message, _>(
Expand All @@ -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
Expand All @@ -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(())
Expand All @@ -98,19 +98,19 @@ 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())
}
},
None => {
let e = anyhow!(
"Missing attributes, message ID is `{}`",
"missing attributes, message ID is `{}`",
received_message.message.id
);
Err(e.into())
Expand Down
7 changes: 2 additions & 5 deletions src/publisher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl PubSubClient {
) -> Result<Vec<String>, 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() {
Expand All @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion src/subscriber/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl PubSubClient {
) -> Result<Vec<RawPulledMessageEnvelope>, 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() {
Expand Down

0 comments on commit 42be672

Please sign in to comment.