Skip to content

Commit

Permalink
Fix bug that was blocking debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
nolancon committed May 31, 2024
1 parent 48aae79 commit 374511b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ var defaultZapConfig = map[string]string{

//nolint:maintidx // Function requires a lot of setup operations.
func main() {
// This is a test.
var (
app = kingpin.New(filepath.Base(os.Args[0]), "Ceph support for Crossplane.").DefaultEnvars()
leaderElection = app.Flag("leader-election", "Use leader election for the controller manager.").Short('l').Default("false").OverrideDefaultFromEnvar("LEADER_ELECTION").Bool()
Expand Down Expand Up @@ -112,6 +111,8 @@ func main() {
)

var zo zap.Options
var zapDevel *bool

zapFlagSet := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
zo.BindFlags(zapFlagSet)

Expand All @@ -121,14 +122,18 @@ func main() {
if !ok {
defaultValue = f.DefValue
}

kf := app.Flag(f.Name, f.Usage).Default(defaultValue)

switch f.Name {
case "zap-devel":
d := kf.Bool()
// Store the value for zap-devel for use when we come to zap-log-level so that we
// do not overwrite the level. VisitAll visits flags in lexicographical order so it
// is safe to assume "zap-devel" will always be visited before "zap-log-level".
zapDevel = kf.Bool()
zapOpts = append(zapOpts, func(o *zap.Options) {
o.Development = *d
if *zapDevel {
o.Development = true
}
})
case "zap-encoder":
e := kf.String()
Expand All @@ -148,6 +153,10 @@ func main() {
zapOpts = append(zapOpts, func(o *zap.Options) {
l := zapcore.Level(0)
app.FatalIfError(l.Set(*ll), "Unable to unmarshal zap-log-level")
// if zap-devel is enabled, the log level should be debug (-1).
if *zapDevel {
l = zapcore.Level(-1)
}
o.Level = l
})
case "zap-stacktrace-level":
Expand All @@ -173,7 +182,6 @@ func main() {
klog.SetLogger(zl)

log := logging.NewLogrLogger(zl.WithName("provider-ceph"))

// Init otel tracer provider if the user sets the flag
if *tracesEnabled {
flush, err := traces.InitTracerProvider(log, *tracesExportAddress, *tracesExportTimeout, *tracesExportInterval)
Expand Down

0 comments on commit 374511b

Please sign in to comment.