Skip to content

Commit

Permalink
Fix grpc log format
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
  • Loading branch information
serathius committed Feb 15, 2024
1 parent 74e3527 commit 6440bc0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion client/v3/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func init() {
if err != nil {
panic(err)
}
grpclog.SetLoggerV2(zapgrpc.NewLogger(lg.Named("grpc")))
lg = lg.Named("etcd-client")
grpclog.SetLoggerV2(zapgrpc.NewLogger(lg))
}
}

Expand Down
5 changes: 3 additions & 2 deletions etcdctl/ctlv3/command/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"go.uber.org/zap"
"go.uber.org/zap/zapgrpc"
"google.golang.org/grpc/grpclog"

"go.etcd.io/etcd/client/pkg/v3/logutil"
Expand Down Expand Up @@ -107,7 +108,6 @@ func clientConfigFromCmd(cmd *cobra.Command) *clientv3.ConfigSpec {
cobrautl.ExitWithError(cobrautl.ExitError, err)
}
if debug {
grpclog.SetLoggerV2(grpclog.NewLoggerV2WithVerbosity(os.Stderr, os.Stderr, os.Stderr, 4))
fs.VisitAll(func(f *pflag.Flag) {
fmt.Fprintf(os.Stderr, "%s=%v\n", flags.FlagToEnv("ETCDCTL", f.Name), f.Value)
})
Expand All @@ -116,8 +116,9 @@ func clientConfigFromCmd(cmd *cobra.Command) *clientv3.ConfigSpec {
// too many routine connection disconnects to turn on by default.
//
// See https://github.com/etcd-io/etcd/pull/9623 for background
grpclog.SetLoggerV2(grpclog.NewLoggerV2(io.Discard, io.Discard, os.Stderr))
lg = lg.WithOptions(zap.IncreaseLevel(zap.ErrorLevel))
}
grpclog.SetLoggerV2(zapgrpc.NewLogger(lg.Named("grpc")))

cfg := &clientv3.ConfigSpec{}
cfg.Endpoints, err = endpointsFromCmd(cmd)
Expand Down
8 changes: 3 additions & 5 deletions server/embed/config_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"net/url"
"os"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand Down Expand Up @@ -227,13 +225,13 @@ func NewZapCoreLoggerBuilder(lg *zap.Logger, _ zapcore.Core, _ zapcore.WriteSync
func (cfg *Config) SetupGlobalLoggers() {
lg := cfg.GetLogger()
if lg != nil {
zap.ReplaceGlobals(lg)
if cfg.LogLevel == "debug" {
grpc.EnableTracing = true
grpclog.SetLoggerV2(zapgrpc.NewLogger(lg))
} else {
grpclog.SetLoggerV2(grpclog.NewLoggerV2(io.Discard, os.Stderr, os.Stderr))
lg = lg.WithOptions(zap.IncreaseLevel(zap.WarnLevel))
}
zap.ReplaceGlobals(lg)
grpclog.SetLoggerV2(zapgrpc.NewLogger(lg.Named("grpc")))
}
}

Expand Down
2 changes: 1 addition & 1 deletion server/etcdmain/grpc_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func startGRPCProxy(cmd *cobra.Command, args []string) {
}
defer lg.Sync()

grpclog.SetLoggerV2(zapgrpc.NewLogger(lg))
grpclog.SetLoggerV2(zapgrpc.NewLogger(lg.Named("grpc")))

// The proxy itself (ListenCert) can have not-empty CN.
// The empty CN is required for grpcProxyCert.
Expand Down

0 comments on commit 6440bc0

Please sign in to comment.