From 766b227da2d6afa10cba017693ce49db63a7c09b Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Mon, 26 Aug 2024 15:07:02 +0200 Subject: [PATCH] sql: only raise transaction log level to warn after 1s --- internal/sql/sql.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/sql/sql.go b/internal/sql/sql.go index b677e97fd..2b5920f9d 100644 --- a/internal/sql/sql.go +++ b/internal/sql/sql.go @@ -12,6 +12,7 @@ import ( "time" "go.uber.org/zap" + "go.uber.org/zap/zapcore" "lukechampine.com/frand" ) @@ -172,7 +173,11 @@ LOOP: if sleep > maxBackoff { sleep = maxBackoff } - log.Warn("database locked", zap.Duration("elapsed", time.Since(attemptStart)), zap.Duration("totalElapsed", time.Since(start)), zap.Stack("stack"), zap.Duration("retry", sleep)) + lvl := zapcore.DebugLevel + if time.Since(start) > time.Second { + lvl = zapcore.WarnLevel + } + log.Log(lvl, "database locked", zap.Duration("elapsed", time.Since(attemptStart)), zap.Duration("totalElapsed", time.Since(start)), zap.Stack("stack"), zap.Duration("retry", sleep)) select { case <-ctx.Done():