Skip to content

Commit 6a1a972

Browse files
authored
Add support to entry caller in logstash JSON (#67)
Signed-off-by: Boaz Shuster <[email protected]>
1 parent dc7eb8c commit 6a1a972

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

hook.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package logrustash
22

33
import (
4+
"fmt"
45
"io"
56
"sync"
67

@@ -64,6 +65,12 @@ func copyEntry(e *logrus.Entry, fields logrus.Fields) *logrus.Entry {
6465
ne.Level = e.Level
6566
ne.Time = e.Time
6667
ne.Data = logrus.Fields{}
68+
69+
if e.HasCaller() {
70+
ne.Data["function"] = e.Caller.Function
71+
ne.Data["file"] = fmt.Sprintf("%s:%d", e.Caller.File, e.Caller.Line)
72+
}
73+
6774
for k, v := range fields {
6875
ne.Data[k] = v
6976
}

0 commit comments

Comments
 (0)