mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-22 03:38:41 +02:00
modify log caller
This commit is contained in:
parent
38673521e4
commit
7bebc58381
@ -30,7 +30,7 @@ func TestFilterLevel(t *testing.T) {
|
||||
|
||||
func TestFilterCaller(t *testing.T) {
|
||||
logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller)
|
||||
log := NewFilter(NewFilter(logger))
|
||||
log := NewFilter(logger)
|
||||
log.Log(LevelDebug, "msg1", "te1st debug")
|
||||
logHelper := NewHelper(NewFilter(NewFilter(logger)))
|
||||
logHelper.Log(LevelDebug, "msg1", "te1st debug")
|
||||
@ -65,4 +65,4 @@ func testFilterFunc(level Level, keyvals ...interface{}) bool {
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
17
log/value.go
17
log/value.go
@ -33,17 +33,16 @@ func Value(ctx context.Context, v interface{}) interface{} {
|
||||
func Caller(depth int) Valuer {
|
||||
return func(context.Context) interface{} {
|
||||
_, file, line, _ := runtime.Caller(depth)
|
||||
h := strings.LastIndex(file, "/log/helper.go")
|
||||
f := strings.LastIndex(file, "/log/filter.go")
|
||||
if f > 0 {
|
||||
_, file, line, _ = runtime.Caller(depth + 2)
|
||||
if strings.LastIndex(file, "/log/helper.go") > 0 {
|
||||
_, file, line, _ = runtime.Caller(depth + 3)
|
||||
for true {
|
||||
h := strings.LastIndex(file, "/log/helper.go")
|
||||
f := strings.LastIndex(file, "/log/filter.go")
|
||||
if h > 0 || f > 0 {
|
||||
depth++
|
||||
_, file, line, _ = runtime.Caller(depth)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
if h > 0 {
|
||||
_, file, line, _ = runtime.Caller(depth + 1)
|
||||
}
|
||||
idx := strings.LastIndexByte(file, '/')
|
||||
return file[idx+1:] + ":" + strconv.Itoa(line)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user