fix logger
This commit is contained in:
@ -12,15 +12,17 @@ const (
|
||||
loggerKey = "logger"
|
||||
)
|
||||
|
||||
type ClientCtx struct {
|
||||
type clientCtx struct {
|
||||
context.Context
|
||||
}
|
||||
|
||||
func NewClientContext(config *util.Config, logger *zerolog.Logger) ClientCtx {
|
||||
var ClientState clientCtx
|
||||
|
||||
func NewClientContext(config *util.Config, logger *zerolog.Logger) {
|
||||
ctx := context.Context(context.TODO())
|
||||
ctx = context.WithValue(ctx, configKey, config)
|
||||
ctx = context.WithValue(ctx, loggerKey, logger)
|
||||
return ClientCtx{ ctx}
|
||||
ClientState = clientCtx{ctx}
|
||||
}
|
||||
|
||||
func Config(c context.Context) *util.Config {
|
||||
@ -31,7 +33,11 @@ func Config(c context.Context) *util.Config {
|
||||
return cfg
|
||||
}
|
||||
|
||||
func Logger(c context.Context) *zerolog.Logger {
|
||||
func Logger() *zerolog.Logger {
|
||||
return getLogger(ClientState.Context)
|
||||
}
|
||||
|
||||
func getLogger(c context.Context) *zerolog.Logger {
|
||||
logger, ok := c.Value(loggerKey).(*zerolog.Logger)
|
||||
if !ok {
|
||||
panic(fmt.Errorf("no access to logger from context"))
|
||||
|
Reference in New Issue
Block a user