go-waku/logging/context.go

21 lines
431 B
Go
Raw Normal View History

2022-05-27 13:25:06 +00:00
package logging
import (
"context"
"go.uber.org/zap"
)
var logKey = &struct{}{}
// From allows retrieving the Logger from a Context
func From(ctx context.Context) *zap.Logger {
return ctx.Value(logKey).(*zap.Logger)
}
// With associates a Logger with a Context to allow passing
// a logger down the call chain.
func With(ctx context.Context, log *zap.Logger) context.Context {
return context.WithValue(ctx, logKey, log)
}