From 84d3b25a8e289e17af740960febbe43347223df8 Mon Sep 17 00:00:00 2001 From: Rolo Date: Tue, 3 Oct 2023 20:18:16 -0700 Subject: [PATCH 1/3] refactor(logging): change slow query log message Current summary is just a truncated version of the also provided full sql statement. New version attempts to more clearly inform user of what exactly is causing the warn log. This could be considered a breaking change, but given that the summary was just a trucated full statement it should be fine. --- sqlx-core/src/logger.rs | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/sqlx-core/src/logger.rs b/sqlx-core/src/logger.rs index eb13a36813..5ccf3e86ae 100644 --- a/sqlx-core/src/logger.rs +++ b/sqlx-core/src/logger.rs @@ -98,26 +98,19 @@ impl<'q> QueryLogger<'q> { let log_is_enabled = log::log_enabled!(target: "sqlx::query", log_level) || private_tracing_dynamic_enabled!(target: "sqlx::query", tracing_level); if log_is_enabled { - let mut summary = parse_query_summary(&self.sql); - - let sql = if summary != self.sql { - summary.push_str(" …"); - format!( - "\n\n{}\n", - sqlformat::format( - &self.sql, - &sqlformat::QueryParams::None, - sqlformat::FormatOptions::default() - ) + let sql = format!( + "{}\n", + sqlformat::format( + &self.sql, + &sqlformat::QueryParams::None, + sqlformat::FormatOptions::default() ) - } else { - String::new() - }; + ); private_tracing_dynamic_event!( target: "sqlx::query", tracing_level, - summary, + summary = format!("query went over configured duration of {}ms", self.settings.slow_statements_duration.as_millis()), db.statement = sql, rows_affected = self.rows_affected, rows_returned= self.rows_returned, @@ -133,11 +126,3 @@ impl<'q> Drop for QueryLogger<'q> { self.finish(); } } - -pub fn parse_query_summary(sql: &str) -> String { - // For now, just take the first 4 words - sql.split_whitespace() - .take(4) - .collect::>() - .join(" ") -} From cf290890a4f28830fdd2e1629b87b64c0ff61b1a Mon Sep 17 00:00:00 2001 From: Rolo Date: Tue, 3 Oct 2023 20:18:16 -0700 Subject: [PATCH 2/3] refactor(logging): change slow query log message Current summary is just a truncated version of the also provided full sql statement. New version attempts to more clearly inform user of what exactly is causing the warn log. This could be considered a breaking change, but given that the summary was just a trucated full statement it should be fine. --- sqlx-core/src/logger.rs | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/sqlx-core/src/logger.rs b/sqlx-core/src/logger.rs index eb13a36813..5ccf3e86ae 100644 --- a/sqlx-core/src/logger.rs +++ b/sqlx-core/src/logger.rs @@ -98,26 +98,19 @@ impl<'q> QueryLogger<'q> { let log_is_enabled = log::log_enabled!(target: "sqlx::query", log_level) || private_tracing_dynamic_enabled!(target: "sqlx::query", tracing_level); if log_is_enabled { - let mut summary = parse_query_summary(&self.sql); - - let sql = if summary != self.sql { - summary.push_str(" …"); - format!( - "\n\n{}\n", - sqlformat::format( - &self.sql, - &sqlformat::QueryParams::None, - sqlformat::FormatOptions::default() - ) + let sql = format!( + "{}\n", + sqlformat::format( + &self.sql, + &sqlformat::QueryParams::None, + sqlformat::FormatOptions::default() ) - } else { - String::new() - }; + ); private_tracing_dynamic_event!( target: "sqlx::query", tracing_level, - summary, + summary = format!("query went over configured duration of {}ms", self.settings.slow_statements_duration.as_millis()), db.statement = sql, rows_affected = self.rows_affected, rows_returned= self.rows_returned, @@ -133,11 +126,3 @@ impl<'q> Drop for QueryLogger<'q> { self.finish(); } } - -pub fn parse_query_summary(sql: &str) -> String { - // For now, just take the first 4 words - sql.split_whitespace() - .take(4) - .collect::>() - .join(" ") -} From 56199edd0118a0aa2d732525d42910af95a5a9de Mon Sep 17 00:00:00 2001 From: Rolo Date: Mon, 16 Oct 2023 20:13:19 -0700 Subject: [PATCH 3/3] refactor(logger): move `parse_query_summary()` sqlite still makes use of the function --- sqlx-sqlite/src/logger.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sqlx-sqlite/src/logger.rs b/sqlx-sqlite/src/logger.rs index d605ea13a8..eb30181bb6 100644 --- a/sqlx-sqlite/src/logger.rs +++ b/sqlx-sqlite/src/logger.rs @@ -86,3 +86,11 @@ impl<'q, O: Debug + Hash + Eq, R: Debug, P: Debug> Drop for QueryPlanLogger<'q, self.finish(); } } + +fn parse_query_summary(sql: &str) -> String { + // For now, just take the first 4 words + sql.split_whitespace() + .take(4) + .collect::>() + .join(" ") +}