clientv3: Enable balancer logging if ETCD_CLIENT_DEBUG environment variable is set

This commit is contained in:
Joe Betz 2018-06-15 15:32:55 -07:00 committed by Gyuho Lee
parent 6309e4b4cf
commit 8451a1715f
3 changed files with 15 additions and 5 deletions

View File

@ -21,6 +21,7 @@ import (
"fmt"
"net"
"net/url"
"os"
"strconv"
"strings"
"sync"
@ -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,
})
}

View File

@ -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
}

View File

@ -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