summaryrefslogtreecommitdiff
path: root/internal/db
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db')
-rw-r--r--internal/db/bundb/hook.go15
1 files changed, 9 insertions, 6 deletions
diff --git a/internal/db/bundb/hook.go b/internal/db/bundb/hook.go
index f02a1353d..cc71f655b 100644
--- a/internal/db/bundb/hook.go
+++ b/internal/db/bundb/hook.go
@@ -35,21 +35,24 @@ func (queryHook) BeforeQuery(ctx context.Context, _ *bun.QueryEvent) context.Con
// AfterQuery logs the time taken to query, the operation (select, update, etc), and the query itself as translated by bun.
func (queryHook) AfterQuery(ctx context.Context, event *bun.QueryEvent) {
- // Get the DB query duration
+ // Get the database query duration.
dur := time.Since(event.StartTime)
switch {
- // Warn on slow database queries
+ // Warn on slow queries.
case dur > time.Second:
log.WithContext(ctx).
WithFields(kv.Fields{
{"duration", dur},
{"query", event.Query},
- }...).Warn("SLOW DATABASE QUERY")
+ }...).
+ Warn("SLOW DATABASE QUERY")
- // On trace, we log query information,
- // manually crafting so DB query not escaped.
+ // On trace log query info.
case log.Level() >= log.TRACE:
- log.Printf("level=TRACE duration=%s query=%s", dur, event.Query)
+ log.TraceKVs(ctx, kv.Fields{
+ {K: "duration", V: dur},
+ {K: "query", V: event.Query},
+ }...)
}
}