go-zero/core/logx/lesslogger.go

28 lines
725 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package logx
2021-02-20 22:45:58 +08:00
// A LessLogger is a logger that control to log once during the given duration.
2020-07-26 17:09:05 +08:00
type LessLogger struct {
*limitedExecutor
}
2021-02-20 22:45:58 +08:00
// NewLessLogger returns a LessLogger.
2020-07-26 17:09:05 +08:00
func NewLessLogger(milliseconds int) *LessLogger {
return &LessLogger{
limitedExecutor: newLimitedExecutor(milliseconds),
}
}
2021-02-20 22:45:58 +08:00
// Error logs v into error log or discard it if more than once in the given duration.
2020-07-26 17:09:05 +08:00
func (logger *LessLogger) Error(v ...interface{}) {
logger.logOrDiscard(func() {
Error(v...)
})
}
2021-02-20 22:45:58 +08:00
// Errorf logs v with format into error log or discard it if more than once in the given duration.
2020-07-26 17:09:05 +08:00
func (logger *LessLogger) Errorf(format string, v ...interface{}) {
logger.logOrDiscard(func() {
Errorf(format, v...)
})
}