Skip to content

Commit

Permalink
Improve doc for WithContext
Browse files Browse the repository at this point in the history
  • Loading branch information
rs committed Aug 12, 2017
1 parent 2ed2f2c commit 46339da
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 46339da

Please sign in to comment.