Skip to content

Commit

Permalink
Add WithStacktrace untility
Browse files Browse the repository at this point in the history
Doesn't have to get merged, I know I'm looking for it sometimes so it is
good to have knowhow about it somewhere.

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
  • Loading branch information
Jakub Sztandera committed Jul 28, 2021
1 parent 5b4daa4 commit 885db33
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

// StandardLogger provides API compatibility with standard printf loggers
Expand Down Expand Up @@ -73,3 +74,11 @@ func (logger *ZapEventLogger) Warningf(format string, args ...interface{}) {
func FormatRFC3339(t time.Time) string {
return t.UTC().Format(time.RFC3339Nano)
}

func WithStamktrace(l *ZapEventLogger) *ZapEventLogger {
copyLogger := *l
copyLogger.SugaredLogger = *copyLogger.SugaredLogger.Desugar().
WithOptions(zap.AddStacktrace(zapcore.InfoLevel)).Sugar()
copyLogger.skipLogger = *copyLogger.SugaredLogger.Desugar().WithOptions(zap.AddCallerSkip(1)).Sugar()
return &copyLogger
}

0 comments on commit 885db33

Please sign in to comment.