forked from TrueCloudLab/frostfs-node
[#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"
|
"context"
|
||||||
|
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/tracing"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/tracing"
|
||||||
|
qos "git.frostfs.info/TrueCloudLab/frostfs-qos/tagging"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (l *Logger) Debug(ctx context.Context, msg string, fields ...zap.Field) {
|
func (l *Logger) Debug(ctx context.Context, msg string, fields ...zap.Field) {
|
||||||
if traceID := tracing.GetTraceID(ctx); traceID != "" {
|
l.z.Debug(msg, appendContext(ctx, fields...)...)
|
||||||
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) {
|
func (l *Logger) Info(ctx context.Context, msg string, fields ...zap.Field) {
|
||||||
if traceID := tracing.GetTraceID(ctx); traceID != "" {
|
l.z.Info(msg, appendContext(ctx, fields...)...)
|
||||||
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) {
|
func (l *Logger) Warn(ctx context.Context, msg string, fields ...zap.Field) {
|
||||||
if traceID := tracing.GetTraceID(ctx); traceID != "" {
|
l.z.Warn(msg, appendContext(ctx, fields...)...)
|
||||||
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) {
|
func (l *Logger) Error(ctx context.Context, msg string, fields ...zap.Field) {
|
||||||
if traceID := tracing.GetTraceID(ctx); traceID != "" {
|
l.z.Error(msg, appendContext(ctx, fields...)...)
|
||||||
l.z.Error(msg, append(fields, zap.String("trace_id", traceID))...)
|
}
|
||||||
return
|
|
||||||
}
|
func appendContext(ctx context.Context, fields ...zap.Field) []zap.Field {
|
||||||
l.z.Error(msg, fields...)
|
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