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

add nullLogger to disable logging #670

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
31 changes: 31 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,33 @@ type Logger interface {
Panicf(format string, v ...interface{})
}

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

func (nullLogger) Fatal(_ ...interface{}) {
// Do nothing
}

func (nullLogger) Fatalf(_ string, _ ...interface{}) {
// Do nothing
}

func (nullLogger) Print(_ ...interface{}) {
// Do nothing
}

func (nullLogger) Printf(_ string, _ ...interface{}) {
// Do nothing
}

func (nullLogger) Panic(_ ...interface{}) {
// Do nothing
}

func (nullLogger) Panicf(_ string, _ ...interface{}) {
// Do nothing
}

// LoggingCollector provides different methods for collecting and classifying
// log messages.
type LoggingCollector interface {
Expand Down Expand Up @@ -324,6 +351,10 @@ func LC() LoggingCollector {
return defaultLoggingCollector
}

func DisableLogging() {
defaultLoggingCollector.SetLogger(nullLogger{})
}

func init() {
if logLevel := strings.ToUpper(os.Getenv("UPPER_DB_LOG")); logLevel != "" {
for ll := range logLevels {
Expand Down