mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-11 14:53:49 +00:00
3c02937a34
'any' type is supported starting from Go1.18. Let's consistently use it instead of 'interface{}' type across the code base, since `any` is easier to read than 'interface{}'.
59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
package log
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
|
)
|
|
|
|
// Logger is using lib/logger for logging
|
|
// but can be suppressed via Suppress method
|
|
type Logger struct {
|
|
mu sync.RWMutex
|
|
disabled bool
|
|
}
|
|
|
|
// Suppress whether to ignore message logging.
|
|
// Once suppressed, logging continues to be ignored
|
|
// until logger is un-suppressed.
|
|
func (l *Logger) Suppress(v bool) {
|
|
l.mu.Lock()
|
|
l.disabled = v
|
|
l.mu.Unlock()
|
|
}
|
|
|
|
func (l *Logger) isDisabled() bool {
|
|
l.mu.RLock()
|
|
defer l.mu.RUnlock()
|
|
return l.disabled
|
|
}
|
|
|
|
// Errorf logs error message.
|
|
func (l *Logger) Errorf(format string, args ...any) {
|
|
if l.isDisabled() {
|
|
return
|
|
}
|
|
logger.Errorf(format, args...)
|
|
}
|
|
|
|
// Warnf logs warning message.
|
|
func (l *Logger) Warnf(format string, args ...any) {
|
|
if l.isDisabled() {
|
|
return
|
|
}
|
|
logger.Warnf(format, args...)
|
|
}
|
|
|
|
// Infof logs info message.
|
|
func (l *Logger) Infof(format string, args ...any) {
|
|
if l.isDisabled() {
|
|
return
|
|
}
|
|
logger.Infof(format, args...)
|
|
}
|
|
|
|
// Panicf logs panic message and panics.
|
|
// Panicf can't be suppressed
|
|
func (l *Logger) Panicf(format string, args ...any) {
|
|
logger.Panicf(format, args...)
|
|
}
|