[#1437] logger: Use context to log trace id

Signed-off-by: Dmitrii Stepanov
This commit is contained in:
Dmitrii Stepanov 2024-10-18 13:31:53 +03:00
parent fd004add00
commit c16dae8b4d
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0
3 changed files with 59 additions and 8 deletions

40
pkg/util/logger/log.go Normal file
View file

@ -0,0 +1,40 @@
package logger
import (
"context"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/tracing"
"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...)
}
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...)
}
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...)
}
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...)
}