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:
parent
f0c2a6ed90
commit
b9b7888d51
@ -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…
Reference in New Issue
Block a user