add caller info to the testHook
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
This commit is contained in:
parent
56f17a0856
commit
bf9db47e8a
@ -18,7 +18,10 @@ package logtest
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
@ -35,6 +38,7 @@ func WithT(ctx context.Context, t testing.TB) context.Context {
|
|||||||
// Increase debug level for tests
|
// Increase debug level for tests
|
||||||
l.SetLevel(logrus.DebugLevel)
|
l.SetLevel(logrus.DebugLevel)
|
||||||
l.SetOutput(ioutil.Discard)
|
l.SetOutput(ioutil.Discard)
|
||||||
|
l.SetReportCaller(true)
|
||||||
|
|
||||||
// Add testing hook
|
// Add testing hook
|
||||||
l.AddHook(&testHook{
|
l.AddHook(&testHook{
|
||||||
@ -42,6 +46,9 @@ func WithT(ctx context.Context, t testing.TB) context.Context {
|
|||||||
fmt: &logrus.TextFormatter{
|
fmt: &logrus.TextFormatter{
|
||||||
DisableColors: true,
|
DisableColors: true,
|
||||||
TimestampFormat: log.RFC3339NanoFixed,
|
TimestampFormat: log.RFC3339NanoFixed,
|
||||||
|
CallerPrettyfier: func(frame *runtime.Frame) (string, string) {
|
||||||
|
return filepath.Base(frame.Function), fmt.Sprintf("%s:%d", frame.File, frame.Line)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user