1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-18 08:26:45 +02:00
woodpecker/vendor/github.com/rs/zerolog/ctx.go

30 lines
651 B
Go
Raw Normal View History

2017-08-03 21:36:22 +02:00
package zerolog
import (
"context"
"io/ioutil"
)
var disabledLogger = New(ioutil.Discard).Level(Disabled)
type ctxKey struct{}
// WithContext returns a copy of ctx with l associated.
func (l Logger) WithContext(ctx context.Context) context.Context {
if lp, ok := ctx.Value(ctxKey{}).(*Logger); ok {
// Update existing pointer.
*lp = l
return ctx
}
return context.WithValue(ctx, ctxKey{}, &l)
}
// Ctx returns the Logger associated with the ctx. If no logger
// is associated, a disabled logger is returned.
func Ctx(ctx context.Context) Logger {
if l, ok := ctx.Value(ctxKey{}).(*Logger); ok {
return *l
}
return disabledLogger
}