From b9b7888d51074dd5c7779023da2de6720699b261 Mon Sep 17 00:00:00 2001 From: SeniorPlayer <12043634+SeniorPlayer@users.noreply.github.com> Date: Sat, 13 Aug 2022 13:00:02 +0800 Subject: [PATCH] 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 --- log/value.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/log/value.go b/log/value.go index 5aceffeb5..66f0b81c0 100644 --- a/log/value.go +++ b/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) } }