1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
pub struct InfoGuard { instant: std::time::Instant, message: String, } impl InfoGuard { pub fn new(message: String) -> InfoGuard { InfoGuard { instant: std::time::Instant::now(), message, } } } impl Drop for InfoGuard { fn drop(&mut self) { tracing::info!(message=self.message.as_str(), elapsed=tracing::field::debug(self.instant.elapsed())); } }