MCPcopy
hub / github.com/rs/zerolog / WithContext

Method WithContext

ctx.go:33–39  ·  view source on GitHub ↗

WithContext returns a copy of ctx with the receiver attached. The Logger attached to the provided Context (if any) will not be effected. If the receiver's log level is Disabled it will only be attached to the returned Context if the provided Context has a previously attached Logger. If the provided

(ctx context.Context)

Source from the content-addressed store, hash-verified

31// return c.Str("bar", "baz")
32// })
33func (l Logger) WithContext(ctx context.Context) context.Context {
34 if _, ok := ctx.Value(ctxKey{}).(*Logger); !ok && l.level == Disabled {
35 // Do not store disabled logger.
36 return ctx
37 }
38 return context.WithValue(ctx, ctxKey{}, &l)
39}
40
41// Ctx returns the Logger associated with the ctx. If no logger
42// is associated, DefaultContextLogger is returned, unless DefaultContextLogger

Callers 6

TestCtxFunction · 0.80
TestCtxDisabledFunction · 0.80
ExampleCtxFunction · 0.80
NewHandlerFunction · 0.80
RequestIDHandlerFunction · 0.80

Calls

no outgoing calls

Tested by 4

TestCtxFunction · 0.64
TestCtxDisabledFunction · 0.64
ExampleCtxFunction · 0.64