diff --git a/logger.go b/logger.go index 929243a2..c483e8b8 100644 --- a/logger.go +++ b/logger.go @@ -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 { @@ -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 {