mirror of https://github.com/sirupsen/logrus.git
support caller manually
This commit is contained in:
parent
6699a89a23
commit
61891c49c9
13
entry.go
13
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)
|
||||
|
|
Loading…
Reference in New Issue