[#1608] logger: Add IO tag logging
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
12da2f8262
commit
170860c14a
1 changed files with 15 additions and 20 deletions
|
@ -4,37 +4,32 @@ import (
|
|||
"context"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/tracing"
|
||||
qos "git.frostfs.info/TrueCloudLab/frostfs-qos/tagging"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func (l *Logger) Debug(ctx context.Context, msg string, fields ...zap.Field) {
|
||||
if traceID := tracing.GetTraceID(ctx); traceID != "" {
|
||||
l.z.Debug(msg, append(fields, zap.String("trace_id", traceID))...)
|
||||
return
|
||||
}
|
||||
l.z.Debug(msg, fields...)
|
||||
l.z.Debug(msg, appendContext(ctx, fields...)...)
|
||||
}
|
||||
|
||||
func (l *Logger) Info(ctx context.Context, msg string, fields ...zap.Field) {
|
||||
if traceID := tracing.GetTraceID(ctx); traceID != "" {
|
||||
l.z.Info(msg, append(fields, zap.String("trace_id", traceID))...)
|
||||
return
|
||||
}
|
||||
l.z.Info(msg, fields...)
|
||||
l.z.Info(msg, appendContext(ctx, fields...)...)
|
||||
}
|
||||
|
||||
func (l *Logger) Warn(ctx context.Context, msg string, fields ...zap.Field) {
|
||||
if traceID := tracing.GetTraceID(ctx); traceID != "" {
|
||||
l.z.Warn(msg, append(fields, zap.String("trace_id", traceID))...)
|
||||
return
|
||||
}
|
||||
l.z.Warn(msg, fields...)
|
||||
l.z.Warn(msg, appendContext(ctx, fields...)...)
|
||||
}
|
||||
|
||||
func (l *Logger) Error(ctx context.Context, msg string, fields ...zap.Field) {
|
||||
if traceID := tracing.GetTraceID(ctx); traceID != "" {
|
||||
l.z.Error(msg, append(fields, zap.String("trace_id", traceID))...)
|
||||
return
|
||||
}
|
||||
l.z.Error(msg, fields...)
|
||||
l.z.Error(msg, appendContext(ctx, fields...)...)
|
||||
}
|
||||
|
||||
func appendContext(ctx context.Context, fields ...zap.Field) []zap.Field {
|
||||
if traceID := tracing.GetTraceID(ctx); traceID != "" {
|
||||
fields = append(fields, zap.String("trace_id", traceID))
|
||||
}
|
||||
if ioTag, ioTagDefined := qos.IOTagFromContext(ctx); ioTagDefined {
|
||||
fields = append(fields, zap.String("io_tag", ioTag))
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue