From 82ff8d96b31ad8240c082fde6cc77c63c575e0ac Mon Sep 17 00:00:00 2001 From: Jayson Reis Date: Fri, 24 Feb 2023 18:16:48 +0100 Subject: [PATCH] chore: Use tracing's fields to get structured logs This also enables on services that can query this data to get useful metrics --- sqlx-core/src/logger.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sqlx-core/src/logger.rs b/sqlx-core/src/logger.rs index 7f9a8ed4ae..eb13a36813 100644 --- a/sqlx-core/src/logger.rs +++ b/sqlx-core/src/logger.rs @@ -114,12 +114,15 @@ impl<'q> QueryLogger<'q> { String::new() }; - let message = format!( - "{}; rows affected: {}, rows returned: {}, elapsed: {:.3?}{}", - summary, self.rows_affected, self.rows_returned, elapsed, sql + private_tracing_dynamic_event!( + target: "sqlx::query", + tracing_level, + summary, + db.statement = sql, + rows_affected = self.rows_affected, + rows_returned= self.rows_returned, + ?elapsed, ); - - private_tracing_dynamic_event!(target: "sqlx::query", tracing_level, message); } } }