Skip to content

Commit 66148f3

Browse files
authored
fix zap-log-level flag (llm-d#827)
1 parent 4edb5b3 commit 66148f3

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

internal/logging/logger.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package logging
22

33
import (
4-
"flag"
5-
64
uberzap "go.uber.org/zap"
75
"go.uber.org/zap/zapcore"
86

@@ -19,14 +17,10 @@ const (
1917

2018
// InitLogging initializes the controller-runtime logger with zap backend.
2119
func InitLogging(opts *zap.Options, logVerbosity *int) {
22-
// Unless -zap-log-level is explicitly set, use -v
23-
useV := true
24-
flag.Visit(func(f *flag.Flag) {
25-
if f.Name == "zap-log-level" {
26-
useV = false
27-
}
28-
})
29-
if useV {
20+
// Unless --zap-log-level is explicitly set (via BindFlags), use -v
21+
// When BindFlags parses --zap-log-level, it sets opts.Level to a non-nil value.
22+
// If opts.Level is still nil, the user didn't set --zap-log-level, so we use -v.
23+
if opts.Level == nil {
3024
// See https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/log/zap#Options.Level
3125
lvl := -1 * (*logVerbosity)
3226
opts.Level = uberzap.NewAtomicLevelAt(zapcore.Level(int8(lvl)))

0 commit comments

Comments
 (0)