Skip to content

Commit

Permalink
Add production/debug log verbosity flag (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
oshoval authored and phoracek committed Oct 7, 2019
1 parent 8ec6e43 commit 7d6339e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ cluster-sync-handler: cluster-sync-resources $(local_handler_manifest)
$(KUBECTL) apply -f deploy/crds/nmstate_v1alpha1_nodenetworkstate_crd.yaml
$(KUBECTL) apply -f deploy/crds/nmstate_v1alpha1_nodenetworkconfigurationpolicy_crd.yaml
$(KUBECTL) delete --ignore-not-found -f $(local_handler_manifest)
$(KUBECTL) create -f $(local_handler_manifest)
# Set debug verbosity level for logs when using cluster-sync
sed "s#--v=production#--v=debug#" $(local_handler_manifest) | $(KUBECTL) create -f -

cluster-sync: cluster-sync-handler

Expand Down
10 changes: 8 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ func printVersion() {
}

func main() {
var logType string

// Add the zap logger flag set to the CLI. The flag set must
// be added before calling pflag.Parse().
pflag.CommandLine.AddFlagSet(zap.FlagSet())

pflag.StringVar(&logType, "v", "production", "Log type (debug/production).")
// Add flags registered by imported packages (e.g. glog and
// controller-runtime)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
Expand All @@ -57,7 +59,11 @@ func main() {
// implementing the logr.Logger interface. This logger will
// be propagated through the whole operator, generating
// uniform and structured logs.
logf.SetLogger(zap.Logger())
if logType == "debug" {
logf.SetLogger(logf.ZapLogger(true))
} else {
logf.SetLogger(logf.ZapLogger(false))
}

printVersion()

Expand Down
2 changes: 2 additions & 0 deletions deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ spec:
effect: NoSchedule
containers:
- name: nmstate-handler
args:
- --v=production
# Replace this with the built image name
image: REPLACE_IMAGE
imagePullPolicy: Always
Expand Down

0 comments on commit 7d6339e

Please sign in to comment.