Skip to content

Commit

Permalink
Direct grpc logs to Zap logger (#1606)
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Shkuro <ys@uber.com>
  • Loading branch information
yurishkuro committed Jun 14, 2019
1 parent 74ff96f commit eb6640b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
15 changes: 11 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions cmd/flags/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ package flags

import (
"flag"
"io/ioutil"
"os"
"os/signal"
"syscall"

grpcZap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
"github.com/pkg/errors"
"github.com/spf13/viper"
"github.com/uber/jaeger-lib/metrics"
"go.uber.org/zap"
"google.golang.org/grpc/grpclog"

"github.com/jaegertracing/jaeger/pkg/healthcheck"
pMetrics "github.com/jaegertracing/jaeger/pkg/metrics"
Expand Down Expand Up @@ -59,8 +58,6 @@ func NewService(adminPort int) *Service {
hcStatusChannel := make(chan healthcheck.Status)
signal.Notify(signalsChannel, os.Interrupt, syscall.SIGTERM)

grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, os.Stderr, os.Stderr))

return &Service{
Admin: NewAdminServer(adminPort),
signalsChannel: signalsChannel,
Expand Down Expand Up @@ -96,6 +93,11 @@ func (s *Service) Start(v *viper.Viper) error {
newProdConfig.Sampling = nil
if logger, err := sFlags.NewLogger(newProdConfig); err == nil {
s.Logger = logger
grpcZap.ReplaceGrpcLogger(logger.WithOptions(
// grpclog is not consistent with the depth of call tree before it's dispatched to zap,
// but Skip(2) still shows grpclog as caller, while Skip(3) shows actual grpc packages.
zap.AddCallerSkip(3),
))
} else {
return errors.Wrap(err, "cannot create logger")
}
Expand Down

0 comments on commit eb6640b

Please sign in to comment.