Skip to content

Commit

Permalink
Merge pull request #252 from cmssczy/add-source-line-in-log
Browse files Browse the repository at this point in the history
add log filename and line number
  • Loading branch information
k8s-ci-robot committed May 11, 2022
2 parents b2b2efc + 1bc605f commit 8da3a0f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
13 changes: 10 additions & 3 deletions test/integration/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 8da3a0f

Please sign in to comment.