Skip to content

Avoid adding test flags when using the null logger #82

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

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pkg/runtime/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"log"

"github.com/go-logr/logr"
tlogr "github.com/go-logr/logr/testing"
"github.com/go-logr/zapr"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -45,7 +44,7 @@ func SetLogger(l logr.Logger) {
// to another logr.Logger. You *must* call SetLogger to
// get any actual logging.
var Log = &DelegatingLogger{
Logger: tlogr.NullLogger{},
Logger: NullLogger{},
promise: &loggerPromise{},
}

Expand Down
44 changes: 44 additions & 0 deletions pkg/runtime/log/null.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package log

import (
"github.com/go-logr/logr"
)

// NB: this is the same as the null logger logr/testing,
// but avoids accidentally adding the testing flags to
// all binaries.

// NullLogger is a logr.Logger that does nothing.
type NullLogger struct{}

var _ logr.Logger = NullLogger{}

// Info implements logr.InfoLogger
func (NullLogger) Info(_ string, _ ...interface{}) {
// Do nothing.
}

// Enabled implements logr.InfoLogger
func (NullLogger) Enabled() bool {
return false
}

// Error implements logr.Logger
func (NullLogger) Error(_ error, _ string, _ ...interface{}) {
// Do nothing.
}

// V implements logr.Logger
func (log NullLogger) V(_ int) logr.InfoLogger {
return log
}

// WithName implements logr.Logger
func (log NullLogger) WithName(_ string) logr.Logger {
return log
}

// WithValues implements logr.Logger
func (log NullLogger) WithValues(_ ...interface{}) logr.Logger {
return log
}