frostfs-node/pkg/util/logger/log.go
Anton Nikiforov 4c4142c5f8 [#1619] logger: Filter entries by tags provided in config
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
2025-02-06 12:06:09 +03:00

64 lines
1.5 KiB
Go

package logger
import (
"context"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/tracing"
"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
}
if traceID := tracing.GetTraceID(ctx); traceID != "" {
l.z.Debug(msg, append(fields, zap.String("trace_id", traceID))...)
return
}
l.z.Debug(msg, fields...)
}
func (l *Logger) Info(ctx context.Context, msg string, fields ...zap.Field) {
if l.denyLogEntry(zapcore.InfoLevel) {
return
}
if traceID := tracing.GetTraceID(ctx); traceID != "" {
l.z.Info(msg, append(fields, zap.String("trace_id", traceID))...)
return
}
l.z.Info(msg, fields...)
}
func (l *Logger) Warn(ctx context.Context, msg string, fields ...zap.Field) {
if l.denyLogEntry(zapcore.WarnLevel) {
return
}
if traceID := tracing.GetTraceID(ctx); traceID != "" {
l.z.Warn(msg, append(fields, zap.String("trace_id", traceID))...)
return
}
l.z.Warn(msg, fields...)
}
func (l *Logger) Error(ctx context.Context, msg string, fields ...zap.Field) {
if l.denyLogEntry(zapcore.ErrorLevel) {
return
}
if traceID := tracing.GetTraceID(ctx); traceID != "" {
l.z.Error(msg, append(fields, zap.String("trace_id", traceID))...)
return
}
l.z.Error(msg, 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 && lvl > level {
return true
}
return false
}