1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-18 08:26:38 +02:00

logger helper to pass down it via context (#1180)

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Vasiliy Tolstov 2020-02-10 00:26:46 +03:00 committed by GitHub
parent ca1d0b94c3
commit c706afcf04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

14
logger/context.go Normal file
View File

@ -0,0 +1,14 @@
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)
}