[#1619] logger: Filter entries by tags provided in config
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
541ee17e13
commit
b86bff746f
8 changed files with 166 additions and 13 deletions
|
@ -6,21 +6,34 @@ import (
|
|||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/tracing"
|
||||
qos "git.frostfs.info/TrueCloudLab/frostfs-qos/tagging"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
func (l *Logger) Debug(ctx context.Context, msg string, fields ...zap.Field) {
|
||||
if l.denyLogEntry(zapcore.DebugLevel) {
|
||||
return
|
||||
}
|
||||
l.z.Debug(msg, appendContext(ctx, fields...)...)
|
||||
}
|
||||
|
||||
func (l *Logger) Info(ctx context.Context, msg string, fields ...zap.Field) {
|
||||
if l.denyLogEntry(zapcore.InfoLevel) {
|
||||
return
|
||||
}
|
||||
l.z.Info(msg, appendContext(ctx, fields...)...)
|
||||
}
|
||||
|
||||
func (l *Logger) Warn(ctx context.Context, msg string, fields ...zap.Field) {
|
||||
if l.denyLogEntry(zapcore.WarnLevel) {
|
||||
return
|
||||
}
|
||||
l.z.Warn(msg, appendContext(ctx, fields...)...)
|
||||
}
|
||||
|
||||
func (l *Logger) Error(ctx context.Context, msg string, fields ...zap.Field) {
|
||||
if l.denyLogEntry(zapcore.ErrorLevel) {
|
||||
return
|
||||
}
|
||||
l.z.Error(msg, appendContext(ctx, fields...)...)
|
||||
}
|
||||
|
||||
|
@ -33,3 +46,14 @@ func appendContext(ctx context.Context, fields ...zap.Field) []zap.Field {
|
|||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
func (l *Logger) denyLogEntry(level zapcore.Level) bool {
|
||||
if l.at.Load()&l.m != l.m {
|
||||
return true
|
||||
}
|
||||
tl := l.tl.Load().(map[uint32]zapcore.Level)
|
||||
if lvl, ok := tl[l.m]; ok {
|
||||
return level < lvl
|
||||
}
|
||||
return level < l.lvl.Level()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue