diff --git a/logging/log.go b/logging/log.go index 859fa6d8..3998352c 100644 --- a/logging/log.go +++ b/logging/log.go @@ -106,14 +106,14 @@ type spanLogger struct { } func (s spanLogger) Log(keyvals ...interface{}) error { - s.kvs = append(s.kvs, keyvals...) for k := range s.kvs { if f, ok := s.kvs[k].(log.Valuer); ok { s.kvs[k] = f() } } + s.kvs = append(s.kvs, keyvals...) s.span.LogKV(s.kvs...) - return s.base.Log(s.kvs...) + return s.base.Log(keyvals...) } // WithContext decorates the log.Logger with information form context. If there is an opentracing span @@ -127,9 +127,11 @@ func WithContext(logger log.Logger, ctx context.Context) log.Logger { args = append(args, kv.Key, kv.Val) } + base := log.With(logger, args...) + span := opentracing.SpanFromContext(ctx) if span == nil { - return withContext(logger, ctx) + return base } return spanLogger{span: span, base: logger, kvs: args} } diff --git a/logging/log_test.go b/logging/log_test.go index a302c56e..3f09ade0 100644 --- a/logging/log_test.go +++ b/logging/log_test.go @@ -65,8 +65,8 @@ func TestSpanLogger(t *testing.T) { spanLogger{ span: &mock, base: log.NewNopLogger(), - kvs: []interface{}{"foo", "bar"}, - }.Log("baz", log.Valuer(func() interface{} { return "qux" })) + kvs: []interface{}{"foo", log.Valuer(func() interface{} { return "bar" })}, + }.Log("baz", "qux") assert.Equal(t, []interface{}{"foo", "bar", "baz", "qux"}, mock.received) }