1
0
mirror of https://github.com/go-kratos/kratos.git synced 2024-12-28 21:09:04 +02:00

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>
This commit is contained in:
SeniorPlayer 2022-08-13 13:00:02 +08:00 committed by GitHub
parent f0c2a6ed90
commit b9b7888d51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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