micro/logger/context.go
Vasiliy Tolstov a9eff06976
fix repocard issues (#2)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-11-02 13:25:29 +03:00

17 lines
385 B
Go

package logger
import "context"
type loggerKey struct{}
// FromContext returns logger from passed context
func FromContext(ctx context.Context) (Logger, bool) {
l, ok := ctx.Value(loggerKey{}).(Logger)
return l, ok
}
// NewContext stores logger into passed context
func NewContext(ctx context.Context, l Logger) context.Context {
return context.WithValue(ctx, loggerKey{}, l)
}