From addf7166e122fe55dc530e102aab263922c0b08f Mon Sep 17 00:00:00 2001 From: Alvar Penning Date: Wed, 7 May 2025 09:25:25 +0200 Subject: [PATCH] icingadb-migrate: Logger for Database connections Setting an explicit logger for the two database connections shows faulty connection attempts directly when they occur and not only after the retry timeout of five minutes. References #949. --- cmd/icingadb-migrate/main.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/icingadb-migrate/main.go b/cmd/icingadb-migrate/main.go index 7b04382f..3dc0dc18 100644 --- a/cmd/icingadb-migrate/main.go +++ b/cmd/icingadb-migrate/main.go @@ -20,7 +20,6 @@ import ( _ "github.com/mattn/go-sqlite3" "github.com/pkg/errors" "github.com/vbauerster/mpb/v6" - "go.uber.org/zap" "golang.org/x/sync/errgroup" "math" "os" @@ -195,17 +194,19 @@ func connectAll(c *Config) (ido, idb *database.DB) { // connect connects to which DB as cfg specifies. (On non-recoverable errors the whole program exits.) func connect(which string, cfg *database.Config) *database.DB { + connectLog := log.With("backend", which) + db, err := database.NewDbFromConfig( cfg, - logging.NewLogger(zap.NewNop().Sugar(), 20*time.Second), + logging.NewLogger(connectLog, 20*time.Second), database.RetryConnectorCallbacks{}, ) if err != nil { - log.With("backend", which).Fatalf("%+v", errors.Wrap(err, "can't connect to database")) + connectLog.Fatalf("%+v", errors.Wrap(err, "can't connect to database")) } if err := db.Ping(); err != nil { - log.With("backend", which).Fatalf("%+v", errors.Wrap(err, "can't connect to database")) + connectLog.Fatalf("%+v", errors.Wrap(err, "can't connect to database")) } return db