From 06222a16dfe7c94579a19b118b11ffac799b7d1a Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Thu, 17 Sep 2020 20:22:03 +0200 Subject: [PATCH] Improve logger handling while connecting to rdbms --- store/rdbms/rdbms.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/store/rdbms/rdbms.go b/store/rdbms/rdbms.go index e48ad17b9..fce370d3e 100644 --- a/store/rdbms/rdbms.go +++ b/store/rdbms/rdbms.go @@ -135,6 +135,11 @@ func (s Store) tryToConnect(ctx context.Context, db *sqlx.DB) error { var ( err error try = 0 + + log = s.log(ctx). + // Make a small adjustment when + // collecting callers from the callstack for this + WithOptions(zap.AddCallerSkip(-2)) ) for { @@ -150,7 +155,7 @@ func (s Store) tryToConnect(ctx context.Context, db *sqlx.DB) error { if time.Now().After(patience) { // don't make too much fuss // if we're in patience mode - s.log(ctx).Warn( + log.Warn( "could not connect to the database", zap.Error(err), zap.Int("try", try), @@ -168,11 +173,7 @@ func (s Store) tryToConnect(ctx context.Context, db *sqlx.DB) error { } } - s.log(ctx). - // Make a small adjustment when - // collecting callers from the callstack for this - WithOptions(zap.AddCallerSkip(-2)). - Debug("connected to the database") + log.Debug("connected to the database") break }