1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-08-04 21:42:57 +02:00

etcd can set log config

default log level is info, which will log o log of unused logs
This commit is contained in:
johnson
2019-12-13 11:22:05 +08:00
parent 885ba8f905
commit 11e42aac69
3 changed files with 19 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import (
"github.com/micro/go-micro/registry"
"github.com/micro/go-micro/util/log"
hash "github.com/mitchellh/hashstructure"
"go.uber.org/zap"
)
var (
@ -73,6 +74,10 @@ func configure(e *etcdRegistry, opts ...registry.Option) error {
config.Username = u.Username
config.Password = u.Password
}
cfg, ok := e.options.Context.Value(logConfigKey{}).(*zap.Config)
if ok && cfg != nil {
config.LogConfig = cfg
}
}
var cAddrs []string

View File

@ -4,10 +4,13 @@ import (
"context"
"github.com/micro/go-micro/registry"
"go.uber.org/zap"
)
type authKey struct{}
type logConfigKey struct{}
type authCreds struct {
Username string
Password string
@ -22,3 +25,13 @@ func Auth(username, password string) registry.Option {
o.Context = context.WithValue(o.Context, authKey{}, &authCreds{Username: username, Password: password})
}
}
// LogConfig allows you to set etcd log config
func LogConfig(config *zap.Config) registry.Option {
return func(o *registry.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, authKey{}, config)
}
}