Skip to content

Commit

Permalink
clientv3: configurable grpc logger
Browse files Browse the repository at this point in the history
  • Loading branch information
gyuho committed Mar 27, 2016
1 parent b8fc61b commit 26627d7
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions clientv3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package clientv3
import (
"crypto/tls"
"errors"
"io/ioutil"
"log"
"net"
"net/url"
"strings"
Expand All @@ -26,6 +28,7 @@ import (
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/grpclog"
)

var (
Expand All @@ -49,6 +52,8 @@ type Client struct {

ctx context.Context
cancel context.CancelFunc

logger grpclog.Logger
}

// EndpointDialer is a policy for choosing which endpoint to dial next
Expand All @@ -66,6 +71,10 @@ type Config struct {

// TLS holds the client secure credentials, if any.
TLS *tls.Config

// Logger defines client-sider log interface.
// If Logger is nil, logging will be ignored, including gRPC log.
Logger grpclog.Logger
}

// New creates a new etcdv3 client from a given configuration.
Expand Down Expand Up @@ -180,6 +189,15 @@ func newClient(cfg *Config) (*Client, error) {
client.Watcher = NewWatcher(client)
client.Auth = NewAuth(client)
client.Maintenance = &maintenance{c: client}
if cfg.Logger == nil {
// same as default std logger
client.logger = log.New(ioutil.Discard, "", 0)
// disable client side grpc by default
grpclog.SetLogger(log.New(ioutil.Discard, "", 0))
} else {
client.logger = cfg.Logger
grpclog.SetLogger(cfg.Logger)
}

return client, nil
}
Expand Down

0 comments on commit 26627d7

Please sign in to comment.