Skip to content

Commit bf9db47

Browse files
committed
add caller info to the testHook
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
1 parent 56f17a0 commit bf9db47

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

log/logtest/context.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ package logtest
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"io/ioutil"
23+
"path/filepath"
24+
"runtime"
2225
"testing"
2326

2427
"github.com/containerd/containerd/log"
@@ -35,13 +38,17 @@ func WithT(ctx context.Context, t testing.TB) context.Context {
3538
// Increase debug level for tests
3639
l.SetLevel(logrus.DebugLevel)
3740
l.SetOutput(ioutil.Discard)
41+
l.SetReportCaller(true)
3842

3943
// Add testing hook
4044
l.AddHook(&testHook{
4145
t: t,
4246
fmt: &logrus.TextFormatter{
4347
DisableColors: true,
4448
TimestampFormat: log.RFC3339NanoFixed,
49+
CallerPrettyfier: func(frame *runtime.Frame) (string, string) {
50+
return filepath.Base(frame.Function), fmt.Sprintf("%s:%d", frame.File, frame.Line)
51+
},
4552
},
4653
})
4754

0 commit comments

Comments
 (0)