From feb27b9907d002d2a16ef0a33d89a964c607c15f Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Mon, 15 Apr 2024 10:10:56 +0200 Subject: [PATCH] e2e framework: configure Ginkgo logger and klog consistently Even if the textlogger which writes to Ginkgo is installed as the logger in klog, klog still does some verbosity checks itself (for example, klog.V().Enabled). Therefore the framework has to keep the verbosity settings in the textlogger and in klog consistent. This is done by wrapping the Set call instead of replacing it. --- test/e2e/framework/ginkgologger.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/test/e2e/framework/ginkgologger.go b/test/e2e/framework/ginkgologger.go index 05f22eff387..6e2c9569970 100644 --- a/test/e2e/framework/ginkgologger.go +++ b/test/e2e/framework/ginkgologger.go @@ -49,14 +49,16 @@ var ( func init() { // ktesting and testinit already registered the -v and -vmodule - // command line flags. To configure the textlogger instead, we - // need to swap out the flag.Value for those. + // command line flags. To configure the textlogger and klog + // consistently, we need to intercept the Set call. This + // can be done by swapping out the flag.Value for the -v and + // -vmodule flags with a wrapper which calls both. var fs flag.FlagSet logConfig.AddFlags(&fs) fs.VisitAll(func(loggerFlag *flag.Flag) { klogFlag := flag.CommandLine.Lookup(loggerFlag.Name) if klogFlag != nil { - klogFlag.Value = loggerFlag.Value + klogFlag.Value = &valueChain{Value: loggerFlag.Value, parentValue: klogFlag.Value} } }) @@ -75,6 +77,21 @@ func init() { klog.SetLoggerWithOptions(ginkgoLogger, opts...) } +type valueChain struct { + flag.Value + parentValue flag.Value +} + +func (v *valueChain) Set(value string) error { + if err := v.Value.Set(value); err != nil { + return err + } + if err := v.parentValue.Set(value); err != nil { + return err + } + return nil +} + func unwind(skip int) (string, int) { location := ginkgotypes.NewCodeLocation(skip + 1) return location.FileName, location.LineNumber