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.
|
2023-01-24 16:32:02 +08:00
|
|
|
func (logger *LessLogger) Error(v ...any) {
|
2020-07-26 17:09:05 +08:00
|
|
|
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.
|
2023-01-24 16:32:02 +08:00
|
|
|
func (logger *LessLogger) Errorf(format string, v ...any) {
|
2020-07-26 17:09:05 +08:00
|
|
|
logger.logOrDiscard(func() {
|
|
|
|
Errorf(format, v...)
|
|
|
|
})
|
|
|
|
}
|