Skip to content

Commit

Permalink
fix: --zap-log-level not take effect (#6465)
Browse files Browse the repository at this point in the history
Signed-off-by: drivebyer <[email protected]>
  • Loading branch information
drivebyer authored Jan 20, 2024
1 parent 2a78700 commit 2c7bcab
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,19 @@ func setupFlags() {

flag.String(kubeContextsFlagKey.String(), "", "Kube contexts the manager will talk to.")

opts := zap.Options{
Development: false,
}
opts.BindFlags(flag.CommandLine)

pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()

// NOTES:
// zap is "Blazing fast, structured, leveled logging in Go.", DON'T event try
// to refactor this logging lib to anything else. Check FAQ - https://github.com/uber-go/zap/blob/master/FAQ.md
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

// set normalizeFunc to replace flag name to viper name
normalizeFunc := pflag.CommandLine.GetNormalizeFunc()
pflag.CommandLine.SetNormalizeFunc(func(fs *pflag.FlagSet, name string) pflag.NormalizedName {
Expand All @@ -172,18 +182,6 @@ func setupFlags() {
}
}

func setupLogger() {
opts := zap.Options{
Development: false,
}
opts.BindFlags(flag.CommandLine)

// NOTES:
// zap is "Blazing fast, structured, leveled logging in Go.", DON'T event try
// to refactor this logging lib to anything else. Check FAQ - https://github.com/uber-go/zap/blob/master/FAQ.md
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
}

func validateRequiredToParseConfigs() error {
validateTolerations := func(val string) error {
if val == "" {
Expand Down Expand Up @@ -237,8 +235,6 @@ func main() {
err error
)

setupLogger()

setupFlags()

// Find and read the config file
Expand Down

0 comments on commit 2c7bcab

Please sign in to comment.