File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package logging
22
33import (
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.
2119func 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 )))
You can’t perform that action at this time.
0 commit comments