Skip to content

Commit

Permalink
Merge pull request #5125 from Iceber/add-caller-info
Browse files Browse the repository at this point in the history
  • Loading branch information
dmcgowan committed Mar 23, 2021
2 parents 717dde3 + bf9db47 commit d54225c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions log/logtest/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ package logtest

import (
"context"
"fmt"
"io/ioutil"
"path/filepath"
"runtime"
"testing"

"github.com/containerd/containerd/log"
Expand All @@ -35,13 +38,17 @@ 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{
t: t,
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)
},
},
})

Expand Down

0 comments on commit d54225c

Please sign in to comment.