Use Display impl to log fields in structured log

Where we already use it, use the % sigil to inform tracing we want to
use the display impl of the fields to log them.

Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
Lee Smet
2024-07-03 10:39:22 +02:00
parent 63e6b62fb7
commit 17c8d6f468
4 changed files with 20 additions and 20 deletions
+6 -6
View File
@@ -249,9 +249,9 @@ impl<O> Drop for RouteEntryGuard<'_, '_, O> {
tokio::select! {
_ = cancellation_token.cancelled() => {}
_ = tokio::time::sleep_until(expiration) => {
debug!(route_key = ?rk, "Expired route entry for route key");
debug!(route_key = %rk, "Expired route entry for route key");
if let Err(e) = expired_route_entry_sink.send(rk).await {
error!(route_key = ?e.0, "Failed to send expired route key on cleanup channel");
error!(route_key = %e.0, "Failed to send expired route key on cleanup channel");
}
}
}
@@ -586,7 +586,7 @@ impl Drop for WriteGuard<'_> {
// The route list did not exist, and now it is not empty, so an entry was added. We
// need to add the route list to the routing table.
false if !self.value.is_empty() => {
trace!(subnet = ?self.subnet, "Inserting new route list for subnet");
trace!(subnet = %self.subnet, "Inserting new route list for subnet");
self.writer.append(RoutingTableOplogEntry::Upsert(
self.subnet,
Arc::clone(&self.value),
@@ -595,14 +595,14 @@ impl Drop for WriteGuard<'_> {
// There was an existing route list which is now empty, so the entry for this subnet
// needs to be deleted in the routing table.
true if self.value.is_empty() => {
trace!(subnet = ?self.subnet, "Removing route list for subnet");
trace!(subnet = %self.subnet, "Removing route list for subnet");
self.writer
.append(RoutingTableOplogEntry::Delete(self.subnet));
}
// The value already existed, and was mutably accessed, so it was dissociated. Update
// the routing table to point to the new value.
true => {
trace!(subnet = ?self.subnet, "Updating route list for subnet");
trace!(subnet = %self.subnet, "Updating route list for subnet");
self.writer.append(RoutingTableOplogEntry::Upsert(
self.subnet,
Arc::clone(&self.value),
@@ -611,7 +611,7 @@ impl Drop for WriteGuard<'_> {
// The value did not exist and is still empty, so nothing was added. Nothing to do
// here.
false => {
trace!(subnet = ?self.subnet, "Unknown subnet had no routes and still doesn't have any");
trace!(subnet = %self.subnet, "Unknown subnet had no routes and still doesn't have any");
}
}
+4 -4
View File
@@ -139,13 +139,13 @@ impl Drop for RoutingTableIterMutEntry<'_> {
// There was an existing route list which is now empty, so the entry for this subnet
// needs to be deleted in the routing table.
if self.value.is_empty() {
trace!(subnet = ?self.subnet, "Removing route list for subnet");
trace!(subnet = %self.subnet, "Removing route list for subnet");
writer.append(RoutingTableOplogEntry::Delete(self.subnet));
}
// The value already existed, and was mutably accessed, so it was dissociated. Update
// the routing table to point to the new value.
else {
trace!(subnet = ?self.subnet, "Updating route list for subnet");
trace!(subnet = %self.subnet, "Updating route list for subnet");
writer.append(RoutingTableOplogEntry::Upsert(
self.subnet,
Arc::clone(&self.value),
@@ -242,9 +242,9 @@ impl<O> Drop for IterRouteEntryGuard<'_, '_, O> {
tokio::select! {
_ = cancellation_token.cancelled() => {}
_ = tokio::time::sleep_until(expiration) => {
debug!(route_key = ?rk, "Expired route entry for route key");
debug!(route_key = %rk, "Expired route entry for route key");
if let Err(e) = expired_route_entry_sink.send(rk).await {
error!(route_key = ?e.0, "Failed to send expired route key on cleanup channel");
error!(route_key = %e.0, "Failed to send expired route key on cleanup channel");
}
}
}
+2 -2
View File
@@ -87,7 +87,7 @@ impl SeqnoCache {
info.targets.push(target);
} else {
debug!(
seqno_request = ?request,
seqno_request = %request,
"Already sent seqno request to target {}",
target.connection_identifier()
);
@@ -96,7 +96,7 @@ impl SeqnoCache {
if !info.sources.contains(&source) {
info.sources.push(source);
} else {
debug!(seqno_request = ?request, "Peer {} is requesting the same seqno again", source.connection_identifier());
debug!(seqno_request = %request, "Peer {} is requesting the same seqno again", source.connection_identifier());
}
}
}
+8 -8
View File
@@ -148,14 +148,6 @@ impl fmt::Display for Subnet {
}
}
impl fmt::Display for PrefixLenError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Invalid prefix length for this address")
}
}
impl std::error::Error for PrefixLenError {}
impl PartialEq for Subnet {
fn eq(&self, other: &Self) -> bool {
// Quic check, subnets of different sizes are never equal.
@@ -178,6 +170,14 @@ impl Hash for Subnet {
}
}
impl fmt::Display for PrefixLenError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Invalid prefix length for this address")
}
}
impl std::error::Error for PrefixLenError {}
#[cfg(test)]
mod tests {
use std::net::{Ipv4Addr, Ipv6Addr};