zlog/ctx.go

17 lines
394 B
Go
Raw Normal View History

2017-05-19 19:59:10 +00:00
package zerolog
import "context"
type ctxKey struct{}
// WithContext returns a copy of ctx with l associated.
func (l Logger) WithContext(ctx context.Context) context.Context {
return context.WithValue(ctx, ctxKey{}, l)
}
// FromContext returns the Logger associated with the ctx.
func FromContext(ctx context.Context) (l Logger, ok bool) {
l, ok = ctx.Value(ctxKey{}).(Logger)
return
}