Skip to content

Commit d54225c

Browse files
authored
Merge pull request #5125 from Iceber/add-caller-info
2 parents 717dde3 + bf9db47 commit d54225c

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

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)