Skip to content

Commit

Permalink
support caller manually
Browse files Browse the repository at this point in the history
  • Loading branch information
cgxxv committed Sep 16, 2020
1 parent 7b88485 commit 495016b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ func (entry *Entry) String() (string, error) {
return str, nil
}

// Add a caller field to the Entry.
func (entry *Entry) WithCaller() *Entry {
frame := getCaller()
if frame != nil {
return entry.WithFields(Fields{
FieldKeyFile: fmt.Sprintf("%s:%d", frame.File, frame.Line),
FieldKeyFunc: frame.Function,
})
}

return entry
}

// Add an error as single field (using the key defined in ErrorKey) to the Entry.
func (entry *Entry) WithError(err error) *Entry {
return entry.WithField(ErrorKey, err)
Expand Down

0 comments on commit 495016b

Please sign in to comment.