Skip to content

Commit fee76af

Browse files
committed
set loggers in 'up local' and test code
1 parent bf6e67a commit fee76af

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

commands/operator-sdk/cmd/up/local.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/spf13/cobra"
3939
"sigs.k8s.io/controller-runtime/pkg/client/config"
4040
"sigs.k8s.io/controller-runtime/pkg/manager"
41+
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
4142
)
4243

4344
func NewLocalCmd() *cobra.Command {
@@ -131,6 +132,9 @@ func upLocal() {
131132
func upLocalAnsible() {
132133
// Set the kubeconfig that the manager will be able to grab
133134
os.Setenv(k8sutil.KubeConfigEnvVar, kubeConfig)
135+
136+
logf.SetLogger(logf.ZapLogger(false))
137+
134138
mgr, err := manager.New(config.GetConfigOrDie(), manager.Options{Namespace: namespace})
135139
if err != nil {
136140
log.Fatal(err)

pkg/logutil/log_util.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ import (
2222
// Usage: log.V(LogVerbosity).Info(...)
2323
type LogVerbosity = int
2424

25+
// The default log verbosity, given to the most important log statements,
26+
// is 0: log.V(0).Info(...) == log.Info(...)
27+
//
28+
// HACK: zapr doesn't calculate log levels correctly, so we must set log
29+
// level integers incorrectly (according to logr) for now so they map to zapr's.
2530
const (
26-
// Default of 0. log.V(0).Info(...) == log.Info(...)
27-
_ LogVerbosity = iota
31+
// VDebug == -1. log.V(VDebug).Info(...) == log.Debug(...)
32+
VDebug LogVerbosity = iota - 1
33+
_
2834
// VWarn == 1. log.V(VWarn).Info(...) == log.Warn(...)
2935
VWarn
30-
// VDebug == 2. log.V(VDebug).Info(...) == log.Debug(...)
31-
VDebug
3236
)
3337

3438
// SDKLog is the parent logger for logs generated by operator code.

test/ansible-operator/cmd/ansible-operator/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
log "github.com/sirupsen/logrus"
2828
"sigs.k8s.io/controller-runtime/pkg/client/config"
2929
"sigs.k8s.io/controller-runtime/pkg/manager"
30+
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
3031
)
3132

3233
func printVersion() {
@@ -38,6 +39,8 @@ func printVersion() {
3839
func main() {
3940
flag.Parse()
4041

42+
logf.SetLogger(logf.ZapLogger(true))
43+
4144
namespace, err := k8sutil.GetWatchNamespace()
4245
if err != nil {
4346
log.Fatalf("failed to get watch namespace: (%v)", err)

0 commit comments

Comments
 (0)