github.com/lingyao2333/mo-zero@v1.4.1/core/logx/lesslogger.go (about) 1 package logx 2 3 // A LessLogger is a logger that control to log once during the given duration. 4 type LessLogger struct { 5 *limitedExecutor 6 } 7 8 // NewLessLogger returns a LessLogger. 9 func NewLessLogger(milliseconds int) *LessLogger { 10 return &LessLogger{ 11 limitedExecutor: newLimitedExecutor(milliseconds), 12 } 13 } 14 15 // Error logs v into error log or discard it if more than once in the given duration. 16 func (logger *LessLogger) Error(v ...interface{}) { 17 logger.logOrDiscard(func() { 18 Error(v...) 19 }) 20 } 21 22 // Errorf logs v with format into error log or discard it if more than once in the given duration. 23 func (logger *LessLogger) Errorf(format string, v ...interface{}) { 24 logger.logOrDiscard(func() { 25 Errorf(format, v...) 26 }) 27 }