Skip to content

Commit

Permalink
add function to caller
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed Sep 26, 2024
1 parent 3ddfda8 commit b5d3164
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,7 @@ func (e *Entry) caller(n int, pc uintptr, fullpath bool) {
return
}

file, line := pcFileLine(pc)
file, line, name := pcFileLineName(pc)
if !fullpath {
var i, j int
for i = len(file) - 1; i >= 0; i-- {
Expand All @@ -1883,9 +1883,17 @@ func (e *Entry) caller(n int, pc uintptr, fullpath bool) {
}
file = file[i+1:]
}
for i = len(name) - 1; i >= 0; i-- {
if name[i] == '/' {
name = name[i+1:]
break
}
}
}

e.buf = append(e.buf, ",\"caller\":\""...)
e.buf = append(e.buf, name...)
e.buf = append(e.buf, ':')
e.buf = append(e.buf, file...)
e.buf = append(e.buf, ':')
e.buf = strconv.AppendInt(e.buf, int64(line), 10)
Expand Down

0 comments on commit b5d3164

Please sign in to comment.