diff --git a/ctx.go b/ctx.go index 966d17ed..44d3f4bc 100644 --- a/ctx.go +++ b/ctx.go @@ -25,9 +25,9 @@ type ctxKey struct{} // l.UpdateContext(func(c Context) Context { // return c.Str("bar", "baz") // }) -func (l *Logger) WithContext(ctx context.Context) context.Context { +func (l Logger) WithContext(ctx context.Context) context.Context { if lp, ok := ctx.Value(ctxKey{}).(*Logger); ok { - if lp == l { + if lp == &l { // Do not store same logger. return ctx } @@ -35,7 +35,7 @@ func (l *Logger) WithContext(ctx context.Context) context.Context { // Do not store disabled logger. return ctx } - return context.WithValue(ctx, ctxKey{}, l) + return context.WithValue(ctx, ctxKey{}, &l) } // Ctx returns the Logger associated with the ctx. If no logger diff --git a/ctx_test.go b/ctx_test.go index 18dbd26b..5bc41e53 100644 --- a/ctx_test.go +++ b/ctx_test.go @@ -45,7 +45,7 @@ func TestCtxDisabled(t *testing.T) { l := New(ioutil.Discard).With().Str("foo", "bar").Logger() ctx = l.WithContext(ctx) - if Ctx(ctx) != &l { + if !reflect.DeepEqual(Ctx(ctx), &l) { t.Error("WithContext did not store logger") } @@ -53,18 +53,18 @@ func TestCtxDisabled(t *testing.T) { return c.Str("bar", "baz") }) ctx = l.WithContext(ctx) - if Ctx(ctx) != &l { + if !reflect.DeepEqual(Ctx(ctx), &l) { t.Error("WithContext did not store updated logger") } l = l.Level(DebugLevel) ctx = l.WithContext(ctx) - if Ctx(ctx) != &l { + if !reflect.DeepEqual(Ctx(ctx), &l) { t.Error("WithContext did not store copied logger") } ctx = dl.WithContext(ctx) - if Ctx(ctx) != &dl { + if !reflect.DeepEqual(Ctx(ctx), &dl) { t.Error("WithContext did not override logger with a disabled logger") } }