mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-11 14:53:49 +00:00
6a7de761f4
* vmalert: support logs suppressing during config reloads The change is mostly required for ENT version of vmalert, since it supports object-storage for config files. Reading data from object storage could be time-consuming, so vmalert emits logs to track the progress. However, these logs are mostly needed on start or on manual config reload. Printing these logs each time `rule.configCheckInterval` is triggered would too verbose. So the change allows to control logs emitting during config reloads. Now, logs are emitted during start up or when SIGHUP is receieved. For periodicall config checks logs emitted by config pkg are suppressed. Signed-off-by: hagen1778 <roman@victoriametrics.com> * vmalert: review fixes Signed-off-by: hagen1778 <roman@victoriametrics.com> --------- Signed-off-by: hagen1778 <roman@victoriametrics.com>
59 lines
1.2 KiB
Go
59 lines
1.2 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 ...interface{}) {
|
|
if l.isDisabled() {
|
|
return
|
|
}
|
|
logger.Errorf(format, args...)
|
|
}
|
|
|
|
// Warnf logs warning message.
|
|
func (l *Logger) Warnf(format string, args ...interface{}) {
|
|
if l.isDisabled() {
|
|
return
|
|
}
|
|
logger.Warnf(format, args...)
|
|
}
|
|
|
|
// Infof logs info message.
|
|
func (l *Logger) Infof(format string, args ...interface{}) {
|
|
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 ...interface{}) {
|
|
logger.Panicf(format, args...)
|
|
}
|