Description
A lot of people will probably agree with me when I say there's room for improvement with how we currently log queries.
-
Logging is very noisy because we always print the whole query at INFO. I think at most we should be printing at
INFO
is the source file and line of the query (which we can do with#[track_caller]
andstd::panic::Location::caller()
), maybe the first couple keywords in the query as context, and the time the query took. We should only be logging the full query (with parameters interpolated) at TRACE. -
Logging is expensive because we pretty-print the SQL. I think we shouldn't be doing nearly that much to it. At most, we should be removing excess indentation so the query isn't weirdly left-padded in logs. I think
sqlformat
can help us there instead of rolling it ourselves. (cc @shssoichiro) -
It doesn't make sense for
ConnectOptions::{log_statements, log_slow_statements}
to take alog::LevelFilter
; instead, it should beOption<log::Level>
. Then, if someone is using a crate liketracing
that includeslog
but doesn't want to uselog
directly, they can still disable query logging by passingNone
(Add a way to disable query logging programmatically #939). -
(Bug) we don't actually obey the log-level setting forDone: fix(logging): make query logging obey level setting forsqlx::query
, only the global log setting. This doesn't need to be innext
, though; I'll be fixing it shortly.sqlx::query
target #945