From ff1e7b531f6438d11b42cd8e50fae72d2abf593e Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 7 Nov 2024 14:37:42 +0300 Subject: [PATCH] [#1437] logger: Add caller skip to log original caller position Signed-off-by: Dmitrii Stepanov --- pkg/util/logger/logger.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/util/logger/logger.go b/pkg/util/logger/logger.go index b3a1b9b94..19d3f1ed1 100644 --- a/pkg/util/logger/logger.go +++ b/pkg/util/logger/logger.go @@ -131,6 +131,7 @@ func newConsoleLogger(prm *Prm) (*Logger, error) { lZap, err := c.Build( zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel)), + zap.AddCallerSkip(1), ) if err != nil { return nil, err @@ -167,7 +168,7 @@ func newJournaldLogger(prm *Prm) (*Logger, error) { zapjournald.SyslogPid(), }) - lZap := zap.New(coreWithContext, zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel))) + lZap := zap.New(coreWithContext, zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel)), zap.AddCallerSkip(1)) l := &Logger{z: lZap, lvl: lvl} prm._log = l @@ -190,6 +191,6 @@ func (l *Logger) With(fields ...zap.Field) *Logger { func NewLoggerWrapper(z *zap.Logger) *Logger { return &Logger{ - z: z, + z: z.WithOptions(zap.AddCallerSkip(1)), } }