2020-02-10 00:26:46 +03:00
|
|
|
package logger
|
|
|
|
|
|
|
|
import "context"
|
|
|
|
|
|
|
|
type loggerKey struct{}
|
|
|
|
|
2020-11-02 13:25:29 +03:00
|
|
|
// FromContext returns logger from passed context
|
2020-02-10 00:26:46 +03:00
|
|
|
func FromContext(ctx context.Context) (Logger, bool) {
|
|
|
|
l, ok := ctx.Value(loggerKey{}).(Logger)
|
|
|
|
return l, ok
|
|
|
|
}
|
|
|
|
|
2020-11-02 13:25:29 +03:00
|
|
|
// NewContext stores logger into passed context
|
2020-02-10 00:26:46 +03:00
|
|
|
func NewContext(ctx context.Context, l Logger) context.Context {
|
|
|
|
return context.WithValue(ctx, loggerKey{}, l)
|
|
|
|
}
|