blob: 290ae41431b47f909ebab2dc6059139015a3c909 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
package log
import "context"
// logKey is a private context key.
type logKey struct{}
// NewContext returns a new context with logger.
func NewContext(ctx context.Context, v Interface) context.Context {
return context.WithValue(ctx, logKey{}, v)
}
// FromContext returns the logger from context, or log.Log.
func FromContext(ctx context.Context) Interface {
if v, ok := ctx.Value(logKey{}).(Interface); ok {
return v
}
return Log
}
|