Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/log/zap: Adding ability to get client-go and trace level logs #1322

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Changed

- When Helm operator projects are created, the SDK now generates RBAC rules in `deploy/role.yaml` based on the chart's default manifest. ([#1188](https://github.com/operator-framework/operator-sdk/pull/1188))
- When debug level is 3 or higher, we will set the klog verbosity to that level. ([#1322](https://github.com/operator-framework/operator-sdk/pull/1322))

### Deprecated

Expand Down
1 change: 1 addition & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions pkg/log/zap/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
package zap

import (
"flag"
"fmt"
"strconv"
"strings"

"github.com/spf13/pflag"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"k8s.io/klog"
)

var (
Expand All @@ -41,6 +43,7 @@ func init() {
zapFlagSet.Var(&sampleVal, "zap-sample", "Enable zap log sampling. Sampling will be disabled for integer log levels > 1")
}

// FlagSet - The zap logging flagset.
func FlagSet() *pflag.FlagSet {
return zapFlagSet
}
Expand Down Expand Up @@ -112,6 +115,12 @@ func (v *levelValue) Set(l string) error {
}
}
v.level = zapcore.Level(int8(lvl))
// If log level is greater than debug, set glog/klog level to that level.
if lvl < -3 {
fs := flag.NewFlagSet("", flag.ContinueOnError)
klog.InitFlags(fs)
fs.Set("v", fmt.Sprintf("%v", -1*lvl))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the returned error?

}
return nil
}

Expand Down