Skip to content

Commit

Permalink
error output: Use entry time stamps
Browse files Browse the repository at this point in the history
For error cases, use the timestamp attached to the corresponding entry
rather than the current time.
  • Loading branch information
abhinav committed Jan 7, 2021
1 parent eded19e commit a0150fa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"os"
"runtime"
"strings"
"time"

"go.uber.org/zap/zapcore"
)
Expand Down Expand Up @@ -310,7 +309,7 @@ func (log *Logger) check(lvl zapcore.Level, msg string) *zapcore.CheckedEntry {
if log.addCaller {
frame, defined := getCallerFrame(log.callerSkip + callerSkipOffset)
if !defined {
fmt.Fprintf(log.errorOutput, "%v Logger.check error: failed to get caller\n", time.Now().UTC())
fmt.Fprintf(log.errorOutput, "%v Logger.check error: failed to get caller\n", ent.Time.UTC())
log.errorOutput.Sync()
}

Expand Down
4 changes: 2 additions & 2 deletions zapcore/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (ce *CheckedEntry) Write(fields ...Field) {
// If the entry is dirty, log an internal error; because the
// CheckedEntry is being used after it was returned to the pool,
// the message may be an amalgamation from multiple call sites.
fmt.Fprintf(ce.ErrorOutput, "%v Unsafe CheckedEntry re-use near Entry %+v.\n", time.Now(), ce.Entry)
fmt.Fprintf(ce.ErrorOutput, "%v Unsafe CheckedEntry re-use near Entry %+v.\n", ce.Time, ce.Entry)
ce.ErrorOutput.Sync()
}
return
Expand All @@ -221,7 +221,7 @@ func (ce *CheckedEntry) Write(fields ...Field) {
}
if ce.ErrorOutput != nil {
if err != nil {
fmt.Fprintf(ce.ErrorOutput, "%v write error: %v\n", time.Now(), err)
fmt.Fprintf(ce.ErrorOutput, "%v write error: %v\n", ce.Time, err)
ce.ErrorOutput.Sync()
}
}
Expand Down

0 comments on commit a0150fa

Please sign in to comment.