Skip to content

Commit 61891c4

Browse files
committed
support caller manually
1 parent 6699a89 commit 61891c4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

entry.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ func (entry *Entry) String() (string, error) {
9494
return str, nil
9595
}
9696

97+
// Add a caller field to the Entry.
98+
func (entry *Entry) WithCaller() *Entry {
99+
frame := getCaller()
100+
if frame != nil {
101+
return entry.WithFields(Fields{
102+
FieldKeyFile: fmt.Sprintf("%s:%d", frame.File, frame.Line),
103+
FieldKeyFunc: frame.Function,
104+
})
105+
}
106+
107+
return entry
108+
}
109+
97110
// Add an error as single field (using the key defined in ErrorKey) to the Entry.
98111
func (entry *Entry) WithError(err error) *Entry {
99112
return entry.WithField(ErrorKey, err)

0 commit comments

Comments
 (0)