zklogger update

test-errcode
wangchuxiao 1 year ago
parent e2cdc6a645
commit df888d22e7

@ -42,7 +42,7 @@ func run(port int) error {
var client discoveryregistry.SvcDiscoveryRegistry
client, err = openKeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
openKeeper.WithFreq(time.Hour), openKeeper.WithUserNameAndPassword(config.Config.Zookeeper.UserName,
config.Config.Zookeeper.Password), openKeeper.WithRoundRobin(), openKeeper.WithTimeout(10))
config.Config.Zookeeper.Password), openKeeper.WithRoundRobin(), openKeeper.WithTimeout(10), openKeeper.WithLogger(log.NewZkLogger()))
if err != nil {
return err
}

@ -12,6 +12,7 @@ import (
relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/tx"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/unrelation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mw"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome"
openKeeper "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry/zookeeper"
@ -48,7 +49,7 @@ func StartTransfer(prometheusPort int) error {
}
client, err := openKeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
openKeeper.WithFreq(time.Hour), openKeeper.WithRoundRobin(), openKeeper.WithUserNameAndPassword(config.Config.Zookeeper.UserName,
config.Config.Zookeeper.Password), openKeeper.WithTimeout(10))
config.Config.Zookeeper.Password), openKeeper.WithTimeout(10), openKeeper.WithLogger(log.NewZkLogger()))
if err != nil {
return err
}

@ -7,6 +7,10 @@ import (
type ZkLogger struct{}
func NewZkLogger() *ZkLogger {
return &ZkLogger{}
}
func (l *ZkLogger) Printf(format string, a ...interface{}) {
ZInfo(context.Background(), "zookeeper output", "msg", fmt.Sprintf(format, a...))
}

@ -39,6 +39,8 @@ type ZkClient struct {
localConns map[string][]resolver.Address
balancerName string
RoundRobin
logger *log.ZkLogger
}
type ZkOption func(*ZkClient)
@ -74,6 +76,12 @@ func WithTimeout(timeout int) ZkOption {
}
}
func WithLogger(logger *log.ZkLogger) ZkOption {
return func(client *ZkClient) {
client.logger = logger
}
}
func NewClient(zkServers []string, zkRoot string, options ...ZkOption) (*ZkClient, error) {
client := &ZkClient{
zkServers: zkServers,
@ -87,7 +95,7 @@ func NewClient(zkServers []string, zkRoot string, options ...ZkOption) (*ZkClien
for _, option := range options {
option(client)
}
conn, eventChan, err := zk.Connect(zkServers, time.Duration(client.timeout)*time.Second, zk.WithLogInfo(true), zk.WithLogger(&log.ZkLogger{}))
conn, eventChan, err := zk.Connect(zkServers, time.Duration(client.timeout)*time.Second, zk.WithLogInfo(true), zk.WithLogger(client.logger))
if err != nil {
return nil, err
}

@ -7,6 +7,7 @@ import (
"time"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mw"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/network"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome"
@ -27,7 +28,7 @@ func Start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(c
defer listener.Close()
zkClient, err := openKeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
openKeeper.WithFreq(time.Hour), openKeeper.WithUserNameAndPassword(config.Config.Zookeeper.UserName,
config.Config.Zookeeper.Password), openKeeper.WithRoundRobin(), openKeeper.WithTimeout(10))
config.Config.Zookeeper.Password), openKeeper.WithRoundRobin(), openKeeper.WithTimeout(10), openKeeper.WithLogger(log.NewZkLogger()))
if err != nil {
return utils.Wrap1(err)
}

Loading…
Cancel
Save