Improve logging

This commit is contained in:
Jan Trefil 2023-10-12 19:14:50 +02:00
parent 99d5e39ab1
commit 5aff99e218
3 changed files with 17 additions and 17 deletions

View file

@ -150,12 +150,12 @@ pub async fn run(
entry.or_insert(writer);
tracing::info!(
"Created new device {} (name {:?}, vendor {}, product {}, version {})",
id,
name,
vendor,
product,
version
id = %id,
name = ?name,
vendor = %vendor,
product = %product,
version = %version,
"Created new device"
);
}
Update::DestroyDevice { id } => {
@ -166,7 +166,7 @@ pub async fn run(
)));
}
tracing::info!("Destroyed device {}", id);
tracing::info!(id = %id, "Destroyed device");
}
Update::Event { id, event } => {
let writer = writers.get_mut(&id).ok_or_else(|| {
@ -178,7 +178,7 @@ pub async fn run(
writer.write(&event).await.map_err(Error::Input)?;
tracing::trace!("Wrote an event to device {}", id);
tracing::trace!(id = %id, "Wrote an event to device");
}
Update::Ping => {
let duration = start.elapsed();

View file

@ -56,7 +56,7 @@ pub async fn timeout<T: Future<Output = Result<U, Error>>, U>(
) -> Result<U, Error> {
time::timeout(duration, future)
.await
.map_err(|err| Error::new(ErrorKind::TimedOut, err))?
.map_err(|_| Error::new(ErrorKind::TimedOut, "Message timeout"))?
}
#[cfg(test)]

View file

@ -159,7 +159,7 @@ pub async fn run(
}
}
tracing::trace!("Wrote an event to device {}", id);
tracing::trace!(id = %id, "Wrote an event to device");
}
}
}
@ -168,12 +168,12 @@ pub async fn run(
let device = &devices[id];
tracing::info!(
"Registered new device {} (name {:?}, vendor {}, product {}, version {})",
id,
device.name,
device.vendor,
device.product,
device.version
id = %id,
name = ?device.name,
vendor = %device.vendor,
product = %device.product,
version = %device.version,
"Registered new device"
);
}
(id, result) = event => match result {
@ -257,7 +257,7 @@ pub async fn run(
}
devices.remove(id);
tracing::info!("Destroyed device {}", id);
tracing::info!(id = %id, "Destroyed device");
}
Err(err) => return Err(Error::Input(err)),
}