fix:fix log caller error (#1773)

* fix:fix log caller error
pull/1776/head
haiyux 3 years ago committed by GitHub
parent 89583885e4
commit 9bf178b1d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      log/value.go

@ -31,14 +31,15 @@ func Value(ctx context.Context, v interface{}) interface{} {
// Caller returns returns a Valuer that returns a pkg/file:line description of the caller.
func Caller(depth int) Valuer {
return func(context.Context) interface{} {
_, file, line, _ := runtime.Caller(depth)
d := depth
_, file, line, _ := runtime.Caller(d)
if strings.LastIndex(file, "/log/filter.go") > 0 {
depth++
_, file, line, _ = runtime.Caller(depth)
d++
_, file, line, _ = runtime.Caller(d)
}
if strings.LastIndex(file, "/log/helper.go") > 0 {
depth++
_, file, line, _ = runtime.Caller(depth)
d++
_, file, line, _ = runtime.Caller(d)
}
idx := strings.LastIndexByte(file, '/')
return file[idx+1:] + ":" + strconv.Itoa(line)

Loading…
Cancel
Save