From d6c33367c4ea5e2f49ff29d601bab7a5f5079879 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Fri, 8 Sep 2017 14:41:11 -0700 Subject: [PATCH 1/3] clientv3: upgrade grpclog to LoggerV2 grpclog.Logger has been deprecated. --- clientv3/example_test.go | 7 ++++--- clientv3/logger.go | 33 +++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/clientv3/example_test.go b/clientv3/example_test.go index e9987b33914..e486981e5db 100644 --- a/clientv3/example_test.go +++ b/clientv3/example_test.go @@ -17,11 +17,13 @@ package clientv3_test import ( "context" "log" + "os" "time" "github.com/coreos/etcd/clientv3" "github.com/coreos/etcd/pkg/transport" - "github.com/coreos/pkg/capnslog" + + "google.golang.org/grpc/grpclog" ) var ( @@ -31,8 +33,7 @@ var ( ) func Example() { - var plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "clientv3") - clientv3.SetLogger(plog) + clientv3.SetLogger(grpclog.NewLoggerV2(os.Stderr, os.Stderr, os.Stderr)) cli, err := clientv3.New(clientv3.Config{ Endpoints: endpoints, diff --git a/clientv3/logger.go b/clientv3/logger.go index 519db45d8e3..784c395c765 100644 --- a/clientv3/logger.go +++ b/clientv3/logger.go @@ -16,36 +16,35 @@ package clientv3 import ( "io/ioutil" - "log" "sync" "google.golang.org/grpc/grpclog" ) // Logger is the logger used by client library. -// It implements grpclog.Logger interface. -type Logger grpclog.Logger +// It implements grpclog.LoggerV2 interface. +type Logger grpclog.LoggerV2 var ( logger settableLogger ) type settableLogger struct { - l grpclog.Logger + l grpclog.LoggerV2 mu sync.RWMutex } func init() { // disable client side logs by default logger.mu.Lock() - logger.l = log.New(ioutil.Discard, "", 0) + logger.l = grpclog.NewLoggerV2(ioutil.Discard, ioutil.Discard, ioutil.Discard) // logger has to override the grpclog at initialization so that // any changes to the grpclog go through logger with locking // instead of through SetLogger // // now updates only happen through settableLogger.set - grpclog.SetLogger(&logger) + grpclog.SetLoggerV2(&logger) logger.mu.Unlock() } @@ -72,11 +71,25 @@ func (s *settableLogger) get() Logger { return l } -// implement the grpclog.Logger interface +// implement the grpclog.LoggerV2 interface +func (s *settableLogger) Info(args ...interface{}) { s.get().Info(args...) } +func (s *settableLogger) Infof(format string, args ...interface{}) { s.get().Infof(format, args...) } +func (s *settableLogger) Infoln(args ...interface{}) { s.get().Infoln(args...) } +func (s *settableLogger) Warning(args ...interface{}) { s.get().Warning(args...) } +func (s *settableLogger) Warningf(format string, args ...interface{}) { + s.get().Warningf(format, args...) +} +func (s *settableLogger) Warningln(args ...interface{}) { s.get().Warningln(args...) } +func (s *settableLogger) Error(args ...interface{}) { s.get().Error(args...) } +func (s *settableLogger) Errorf(format string, args ...interface{}) { + s.get().Errorf(format, args...) +} +func (s *settableLogger) Errorln(args ...interface{}) { s.get().Errorln(args...) } func (s *settableLogger) Fatal(args ...interface{}) { s.get().Fatal(args...) } func (s *settableLogger) Fatalf(format string, args ...interface{}) { s.get().Fatalf(format, args...) } func (s *settableLogger) Fatalln(args ...interface{}) { s.get().Fatalln(args...) } -func (s *settableLogger) Print(args ...interface{}) { s.get().Print(args...) } -func (s *settableLogger) Printf(format string, args ...interface{}) { s.get().Printf(format, args...) } -func (s *settableLogger) Println(args ...interface{}) { s.get().Println(args...) } +func (s *settableLogger) Print(args ...interface{}) { s.get().Info(args...) } +func (s *settableLogger) Printf(format string, args ...interface{}) { s.get().Infof(format, args...) } +func (s *settableLogger) Println(args ...interface{}) { s.get().Infoln(args...) } +func (s *settableLogger) V(l int) bool { return s.get().V(l) } From f37ff4a4e2e93d67b06a99f23fc299d3db8730fb Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Fri, 8 Sep 2017 14:42:04 -0700 Subject: [PATCH 2/3] v3rpc: use grpclog.LoggerV2 for grpc logs grpclog.Logger has been deprecated. Signed-off-by: Gyu-Ho Lee --- etcdserver/api/v3rpc/grpc.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/etcdserver/api/v3rpc/grpc.go b/etcdserver/api/v3rpc/grpc.go index 3f7cea8ee08..862a7dd3eed 100644 --- a/etcdserver/api/v3rpc/grpc.go +++ b/etcdserver/api/v3rpc/grpc.go @@ -17,6 +17,7 @@ package v3rpc import ( "crypto/tls" "math" + "os" "github.com/coreos/etcd/etcdserver" pb "github.com/coreos/etcd/etcdserver/etcdserverpb" @@ -35,7 +36,7 @@ const ( ) func init() { - grpclog.SetLogger(plog) + grpclog.SetLoggerV2(grpclog.NewLoggerV2(os.Stderr, os.Stderr, os.Stderr)) } func Server(s *etcdserver.EtcdServer, tls *tls.Config) *grpc.Server { From 3b3d392540e64631aa5e15533ef4508fcc93dee5 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Fri, 8 Sep 2017 14:42:30 -0700 Subject: [PATCH 3/3] *: use grpclog.LoggerV2 Signed-off-by: Gyu-Ho Lee --- etcdctl/ctlv3/command/global.go | 4 ++-- tools/benchmark/cmd/util.go | 4 ++-- tools/functional-tester/etcd-tester/stresser.go | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/etcdctl/ctlv3/command/global.go b/etcdctl/ctlv3/command/global.go index b4cf18a9065..eeef3ddb3bc 100644 --- a/etcdctl/ctlv3/command/global.go +++ b/etcdctl/ctlv3/command/global.go @@ -20,7 +20,6 @@ import ( "fmt" "io" "io/ioutil" - "log" "os" "strings" "time" @@ -31,6 +30,7 @@ import ( "github.com/coreos/etcd/pkg/srv" "github.com/coreos/etcd/pkg/transport" "github.com/spf13/cobra" + "google.golang.org/grpc/grpclog" ) // GlobalFlags are flags that defined globally @@ -97,7 +97,7 @@ func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client { ExitWithError(ExitError, derr) } if debug { - clientv3.SetLogger(log.New(os.Stderr, "grpc: ", 0)) + clientv3.SetLogger(grpclog.NewLoggerV2(os.Stderr, os.Stderr, os.Stderr)) } endpoints, err := endpointsFromCmd(cmd) diff --git a/tools/benchmark/cmd/util.go b/tools/benchmark/cmd/util.go index 544dceb297b..c93fdbed570 100644 --- a/tools/benchmark/cmd/util.go +++ b/tools/benchmark/cmd/util.go @@ -18,12 +18,12 @@ import ( "context" "crypto/rand" "fmt" - "log" "os" "strings" "github.com/coreos/etcd/clientv3" "github.com/coreos/etcd/pkg/report" + "google.golang.org/grpc/grpclog" ) var ( @@ -98,7 +98,7 @@ func mustCreateConn() *clientv3.Client { return mustCreateConn() } - clientv3.SetLogger(log.New(os.Stderr, "grpc", 0)) + clientv3.SetLogger(grpclog.NewLoggerV2(os.Stderr, os.Stderr, os.Stderr)) if err != nil { fmt.Fprintf(os.Stderr, "dial error: %v\n", err) diff --git a/tools/functional-tester/etcd-tester/stresser.go b/tools/functional-tester/etcd-tester/stresser.go index 30e8d47d703..4c5cdcef63c 100644 --- a/tools/functional-tester/etcd-tester/stresser.go +++ b/tools/functional-tester/etcd-tester/stresser.go @@ -16,6 +16,7 @@ package main import ( "fmt" + "os" "strings" "sync" "time" @@ -24,7 +25,7 @@ import ( "google.golang.org/grpc/grpclog" ) -func init() { grpclog.SetLogger(plog) } +func init() { grpclog.SetLoggerV2(grpclog.NewLoggerV2(os.Stderr, os.Stderr, os.Stderr)) } type Stresser interface { // Stress starts to stress the etcd cluster