Skip to content

Commit

Permalink
clientv3: Enable balancer logging if ETCD_CLIENT_DEBUG environment va…
Browse files Browse the repository at this point in the history
…riable is set
  • Loading branch information
jpbetz authored and gyuho committed Jun 15, 2018
1 parent 6309e4b commit 8451a17
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
14 changes: 10 additions & 4 deletions clientv3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net"
"net/url"
"os"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -49,13 +50,18 @@ var (
)

func init() {
lg := zap.NewNop()
if os.Getenv("ETCD_CLIENT_DEBUG") != "" {
var err error
lg, err = zap.NewProductionConfig().Build() // info level logging
if err != nil {
panic(err)
}
}
balancer.RegisterBuilder(balancer.Config{
Policy: picker.RoundrobinBalanced,
Name: roundRobinBalancerName,

// TODO: configure from clientv3.Config
Logger: zap.NewNop(),
// Logger: zap.NewExample(),
Logger: lg,
})
}

Expand Down
2 changes: 1 addition & 1 deletion clientv3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type Config struct {

// LogConfig configures client-side logger.
// If nil, use the default logger.
// TODO: configure balancer and gRPC logger
// TODO: configure gRPC logger
LogConfig *zap.Config
}

Expand Down
4 changes: 4 additions & 0 deletions clientv3/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,8 @@
// }
// }
//
// The grpc load balancer is registered statically and is shared across etcd clients.
// To enable detailed load balancer logging, set the ETCD_CLIENT_DEBUG environment
// variable. E.g. "ETCD_CLIENT_DEBUG=1".
//
package clientv3

0 comments on commit 8451a17

Please sign in to comment.