fix(log): DefaultCaller doesn't returns "pkg/file:line", it returns "file:line" now. For example, both biz/user.go and data/user.go are printed as user.go in logger. It's not clear. (#2274)

Co-authored-by: SeniorPlayer <SeniorPlayer@gg.com>
pull/2096/merge
SeniorPlayer 2 years ago committed by GitHub
parent f0c2a6ed90
commit b9b7888d51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      log/value.go

@ -32,6 +32,10 @@ func Caller(depth int) Valuer {
return func(context.Context) interface{} {
_, file, line, _ := runtime.Caller(depth)
idx := strings.LastIndexByte(file, '/')
if idx == -1 {
return file[idx+1:] + ":" + strconv.Itoa(line)
}
idx = strings.LastIndexByte(file[:idx], '/')
return file[idx+1:] + ":" + strconv.Itoa(line)
}
}

Loading…
Cancel
Save