Skip to content

Commit

Permalink
Merge pull request #82 from ipfs/fix/skip-caller
Browse files Browse the repository at this point in the history
fix: skip an additional caller in Warning(f)
  • Loading branch information
Stebalien authored May 5, 2020
2 parents 2f9b338 + b8f13e8 commit 0b3736a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,33 @@ func Logger(system string) *ZapEventLogger {
}

logger := getLogger(system)
skipLogger := logger.With(zap.AddCallerSkip(1))

return &ZapEventLogger{system: system, SugaredLogger: *logger}
return &ZapEventLogger{
system: system,
SugaredLogger: *logger,
skipLogger: *skipLogger,
}
}

// ZapEventLogger implements the EventLogger and wraps a go-logging Logger
type ZapEventLogger struct {
zap.SugaredLogger
system string
// used to fix the caller location when calling Warning and Warningf.
skipLogger zap.SugaredLogger
system string
}

// Warning is for compatibility
// Deprecated: use Warn(args ...interface{}) instead
func (logger *ZapEventLogger) Warning(args ...interface{}) {
logger.Warn(args...)
logger.skipLogger.Warn(args...)
}

// Warningf is for compatibility
// Deprecated: use Warnf(format string, args ...interface{}) instead
func (logger *ZapEventLogger) Warningf(format string, args ...interface{}) {
logger.Warnf(format, args...)
logger.skipLogger.Warnf(format, args...)
}

// FormatRFC3339 returns the given time in UTC with RFC3999Nano format.
Expand Down

0 comments on commit 0b3736a

Please sign in to comment.