diff --git a/entry.go b/entry.go index 5a5cbfe..71b7120 100644 --- a/entry.go +++ b/entry.go @@ -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)