diff options
Diffstat (limited to 'common/loggers/ignorableLogger.go')
-rw-r--r-- | common/loggers/ignorableLogger.go | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/common/loggers/ignorableLogger.go b/common/loggers/ignorableLogger.go index e12e41d68..1bd4d99b8 100644 --- a/common/loggers/ignorableLogger.go +++ b/common/loggers/ignorableLogger.go @@ -19,25 +19,31 @@ import ( ) // IgnorableLogger is a logger that ignores certain log statements. -type IgnorableLogger struct { - logger *Logger +type IgnorableLogger interface { + Logger + Errorsf(statementID, format string, v ...interface{}) +} + +type ignorableLogger struct { + Logger statements map[string]bool } // NewIgnorableLogger wraps the given logger and ignores the log statement IDs given. -func NewIgnorableLogger(logger *Logger, statements ...string) IgnorableLogger { +func NewIgnorableLogger(logger Logger, statements ...string) IgnorableLogger { statementsSet := make(map[string]bool) for _, s := range statements { statementsSet[strings.ToLower(s)] = true } - return IgnorableLogger{ - logger: logger, + return ignorableLogger{ + Logger: logger, statements: statementsSet, } } -func (l IgnorableLogger) Errorf(statementID, format string, v ...interface{}) { +// Errorsf logs statementID as an ERROR if not configured as ignoreable. +func (l ignorableLogger) Errorsf(statementID, format string, v ...interface{}) { if l.statements[statementID] { // Ignore. return @@ -48,5 +54,5 @@ ignoreErrors = [%q]`, statementID) format += ignoreMsg - l.logger.ERROR.Printf(format, v...) + l.Errorf(format, v...) } |