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

Bug 1874647: Initialize controller-runtime logging #771

Merged
merged 1 commit into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions cmd/cluster-network-operator/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"log"

"github.com/go-logr/logr"
crlog "sigs.k8s.io/controller-runtime/pkg/log"
)

func initControllerRuntimeLogging() {
crlog.SetLogger(&crLogger{})
}

type crLogger struct {
logInfo bool
}

func (l *crLogger) Info(msg string, keysAndValues ...interface{}) {
if l.logInfo {
log.Printf("%s", msg)
}
}

func (l *crLogger) Error(err error, msg string, keysAndValues ...interface{}) {
log.Printf("ERROR %v - %s", err, msg)
}

func (l *crLogger) Enabled() bool {
return true
}

func (l *crLogger) V(level int) logr.InfoLogger {
return l
}

func (l *crLogger) WithValues(keysAndValues ...interface{}) logr.Logger {
return l
}

func (l *crLogger) WithName(name string) logr.Logger {
return &crLogger{logInfo: name == "leader"}
}
1 change: 1 addition & 0 deletions cmd/cluster-network-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func init() {
}

func main() {
initControllerRuntimeLogging()
printVersion()
flag.Parse()

Expand Down