2023-03-20 15:08:30 +00:00
|
|
|
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.
|
2024-07-09 22:14:15 +00:00
|
|
|
func (l *Logger) Errorf(format string, args ...any) {
|
2023-03-20 15:08:30 +00:00
|
|
|
if l.isDisabled() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
logger.Errorf(format, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Warnf logs warning message.
|
2024-07-09 22:14:15 +00:00
|
|
|
func (l *Logger) Warnf(format string, args ...any) {
|
2023-03-20 15:08:30 +00:00
|
|
|
if l.isDisabled() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
logger.Warnf(format, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Infof logs info message.
|
2024-07-09 22:14:15 +00:00
|
|
|
func (l *Logger) Infof(format string, args ...any) {
|
2023-03-20 15:08:30 +00:00
|
|
|
if l.isDisabled() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
logger.Infof(format, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Panicf logs panic message and panics.
|
|
|
|
// Panicf can't be suppressed
|
2024-07-09 22:14:15 +00:00
|
|
|
func (l *Logger) Panicf(format string, args ...any) {
|
2023-03-20 15:08:30 +00:00
|
|
|
logger.Panicf(format, args...)
|
|
|
|
}
|