Improve doc for WithContext

This commit is contained in:
Olivier Poitrey 2017-08-12 16:16:31 -07:00
parent 2ed2f2c974
commit 46339da83a
1 changed files with 9 additions and 1 deletions

10
ctx.go
View File

@ -9,7 +9,15 @@ var disabledLogger = New(ioutil.Discard).Level(Disabled)
type ctxKey struct{}
// WithContext returns a copy of ctx with l associated.
// WithContext returns a copy of ctx with l associated. If an instance of Logger
// is already in the context, the pointer to this logger is updated with l.
//
// For instance, to add a field to an existing logger in the context, use this
// notation:
//
// ctx := r.Context()
// l := zerolog.Ctx(ctx)
// ctx = l.With().Str("foo", "bar").WithContext(ctx)
func (l Logger) WithContext(ctx context.Context) context.Context {
if lp, ok := ctx.Value(ctxKey{}).(*Logger); ok {
// Update existing pointer.