forked from TrueCloudLab/frostfs-node
[#1437] logger: Use context to log trace id
Signed-off-by: Dmitrii Stepanov
This commit is contained in:
parent
fd004add00
commit
c16dae8b4d
3 changed files with 59 additions and 8 deletions
40
pkg/util/logger/log.go
Normal file
40
pkg/util/logger/log.go
Normal 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...)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue