From bf9db47e8acde69add45a9f6146d21d293604e5e Mon Sep 17 00:00:00 2001 From: Iceber Gu Date: Sat, 27 Feb 2021 03:49:05 +0800 Subject: [PATCH] add caller info to the testHook Signed-off-by: Iceber Gu --- log/logtest/context.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/log/logtest/context.go b/log/logtest/context.go index 08f6fda20..870c62aa7 100644 --- a/log/logtest/context.go +++ b/log/logtest/context.go @@ -18,7 +18,10 @@ package logtest import ( "context" + "fmt" "io/ioutil" + "path/filepath" + "runtime" "testing" "github.com/containerd/containerd/log" @@ -35,6 +38,7 @@ func WithT(ctx context.Context, t testing.TB) context.Context { // Increase debug level for tests l.SetLevel(logrus.DebugLevel) l.SetOutput(ioutil.Discard) + l.SetReportCaller(true) // Add testing hook l.AddHook(&testHook{ @@ -42,6 +46,9 @@ func WithT(ctx context.Context, t testing.TB) context.Context { fmt: &logrus.TextFormatter{ DisableColors: true, TimestampFormat: log.RFC3339NanoFixed, + CallerPrettyfier: func(frame *runtime.Frame) (string, string) { + return filepath.Base(frame.Function), fmt.Sprintf("%s:%d", frame.File, frame.Line) + }, }, })