Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clientv3: disable client side grpc log #4875

Merged
merged 1 commit into from
Mar 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,12 +28,15 @@ import (
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/grpclog"
)

var (
ErrNoAvailableEndpoints = errors.New("etcdclient: no available endpoints")
)

type Logger grpclog.Logger

// Client provides and manages an etcd v3 client session.
type Client struct {
Cluster
Expand All @@ -49,6 +54,8 @@ type Client struct {

ctx context.Context
cancel context.CancelFunc

logger Logger
}

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

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

// Logger is the logger used by client library.
Logger Logger
}

// New creates a new etcdv3 client from a given configuration.
Expand Down Expand Up @@ -180,6 +190,14 @@ func newClient(cfg *Config) (*Client, error) {
client.Watcher = NewWatcher(client)
client.Auth = NewAuth(client)
client.Maintenance = &maintenance{c: client}
if cfg.Logger == nil {
client.logger = log.New(ioutil.Discard, "", 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment is not accurate. probably just remove the comment. we should always comment why not what. the code itself is the what part.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. Just fixed. Thanks!

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