ceph-csi/vendor/github.com/gemalto/flume/context.go
Rakshith R e72ed593be rebase: vendor files required for kmip
Signed-off-by: Rakshith R <rar@redhat.com>
2022-08-18 07:41:42 +00:00

28 lines
676 B
Go

package flume
import (
"context"
)
// DefaultLogger is returned by FromContext if no other logger has been
// injected into the context.
var DefaultLogger = New("")
type ctxKey struct{}
var loggerKey = &ctxKey{}
// WithLogger returns a new context with the specified logger injected into it.
func WithLogger(ctx context.Context, l Logger) context.Context {
return context.WithValue(ctx, loggerKey, l)
}
// FromContext returns a logger from the context. If the context
// doesn't contain a logger, the DefaultLogger will be returned.
func FromContext(ctx context.Context) Logger {
if l, ok := ctx.Value(loggerKey).(Logger); ok {
return l
}
return DefaultLogger
}