diff --git a/main.go b/main.go index 8057bef33bae..2eddd4499fcf 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ import ( // to ensure that exec-entrypoint and run can make use of them. _ "k8s.io/client-go/plugin/pkg/client/auth" + zaplog "go.uber.org/zap" "go.uber.org/zap/zapcore" schedulingv1 "k8s.io/api/scheduling/v1" "k8s.io/apimachinery/pkg/runtime" @@ -70,6 +71,7 @@ func main() { opts := zap.Options{ TimeEncoder: zapcore.RFC3339NanoTimeEncoder, + ZapOpts: []zaplog.Option{zaplog.AddCaller(), zaplog.AddCallerSkip(-1)}, } opts.BindFlags(flag.CommandLine) flag.Parse() diff --git a/test/integration/framework/framework.go b/test/integration/framework/framework.go index ca5b40bbba12..36c95ee462ab 100644 --- a/test/integration/framework/framework.go +++ b/test/integration/framework/framework.go @@ -25,6 +25,7 @@ import ( "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" + zaplog "go.uber.org/zap" "go.uber.org/zap/zapcore" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" @@ -58,10 +59,16 @@ type Framework struct { } func (f *Framework) Setup() (context.Context, *rest.Config, client.Client) { - logTimeEncodeOpt := func(o *zap.Options) { - o.TimeEncoder = zapcore.RFC3339NanoTimeEncoder + opts := zap.Options{ + TimeEncoder: zapcore.RFC3339NanoTimeEncoder, + ZapOpts: []zaplog.Option{zaplog.AddCaller(), zaplog.AddCallerSkip(-1)}, } - ctrl.SetLogger(zap.New(zap.WriteTo(ginkgo.GinkgoWriter), zap.UseDevMode(true), zap.Level(zapcore.Level(-3)), logTimeEncodeOpt)) + ctrl.SetLogger(zap.New( + zap.WriteTo(ginkgo.GinkgoWriter), + zap.UseDevMode(true), + zap.Level(zapcore.Level(-3)), + zap.UseFlagOptions(&opts)), + ) ginkgo.By("bootstrapping test environment") f.testEnv = &envtest.Environment{