1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-11-30 08:06:40 +02:00
go-micro/logger/context.go
Vasiliy Tolstov c706afcf04
logger helper to pass down it via context (#1180)
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-02-09 21:26:46 +00:00

15 lines
287 B
Go

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