Skip to content

Commit

Permalink
log for enable pass nil context
Browse files Browse the repository at this point in the history
  • Loading branch information
yinheli committed Jul 15, 2021
1 parent c6d159f commit de9e3d5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ func (t defaultLogger) With(fields ...zapcore.Field) Logger {

// For log with context.Context, which will log trace_id and span_id if opentracing enabled
func (t defaultLogger) For(ctx context.Context) Logger {
if ctx == nil {
ctx = context.Background()
}

if span := opentracing.SpanFromContext(ctx); span != nil {
l := spanLogger{span: span, logger: t.logger.WithOptions(zap.AddCallerSkip(t.skip())), additionalFields: t.additionalFields}

Expand Down

0 comments on commit de9e3d5

Please sign in to comment.