Skip to content

Commit

Permalink
Merge pull request #118 from ipfs/feat/with-stacktrace
Browse files Browse the repository at this point in the history
Add WithStacktrace untility
  • Loading branch information
Stebalien committed Aug 3, 2021
2 parents 5b4daa4 + ced9133 commit fbad710
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 WithStacktrace(l *ZapEventLogger, level LogLevel) *ZapEventLogger {
copyLogger := *l
copyLogger.SugaredLogger = *copyLogger.SugaredLogger.Desugar().
WithOptions(zap.AddStacktrace(zapcore.Level(level))).Sugar()
copyLogger.skipLogger = *copyLogger.SugaredLogger.Desugar().WithOptions(zap.AddCallerSkip(1)).Sugar()
return &copyLogger
}

0 comments on commit fbad710

Please sign in to comment.