Skip to content

Commit

Permalink
fix: grpclog data race (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
sysulq committed Oct 26, 2022
1 parent 07fb9a5 commit 24a6708
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 0 additions & 6 deletions pkg/client/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ import (

type ClientConn = grpc.ClientConn

func init() {
// conf.OnLoaded(func(c *conf.Configuration) {
// xgrpclog.SetLogger(xlog.Jupiter().With(xlog.FieldMod("grpc")))
// })
}

func newGRPCClient(config *Config) *grpc.ClientConn {
var ctx = context.Background()

Expand Down
3 changes: 3 additions & 0 deletions pkg/core/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/douyu/jupiter/pkg/core/executor"
"github.com/douyu/jupiter/pkg/core/hooks"
"github.com/douyu/jupiter/pkg/core/signals"
"github.com/douyu/jupiter/pkg/core/xgrpclog"
"github.com/douyu/jupiter/pkg/flag"
"github.com/douyu/jupiter/pkg/registry"
"github.com/douyu/jupiter/pkg/server"
Expand Down Expand Up @@ -109,6 +110,8 @@ func (app *Application) initialize() {

_ = app.parseFlags()
_ = app.printBanner()

xgrpclog.SetLogger(xlog.Jupiter())
})
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/core/xgrpclog/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import (
"google.golang.org/grpc/grpclog"
)

const defaultCallerSkip = 4

// SetLogger sets loggerWrapper to grpclog
func SetLogger(logger *xlog.Logger) {
logger = logger.WithOptions(zap.AddCallerSkip(defaultCallerSkip))
grpclog.SetLoggerV2(&loggerWrapper{logger: logger, sugar: logger.Sugar()})
}

Expand Down

0 comments on commit 24a6708

Please sign in to comment.