From 7388911e0cf878b3198a324820387304478bd95f Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Wed, 5 Apr 2017 10:45:52 -0700 Subject: [PATCH] ctlv3: add '--debug' flag (to enable grpclog) By default, grpclog is disabled. It should be configurable for debugging purposes, as we did in v2. Signed-off-by: Gyu-Ho Lee --- etcdctl/ctlv3/command/global.go | 12 ++++++++++++ etcdctl/ctlv3/ctl.go | 1 + 2 files changed, 13 insertions(+) diff --git a/etcdctl/ctlv3/command/global.go b/etcdctl/ctlv3/command/global.go index c31595650..616d32e21 100644 --- a/etcdctl/ctlv3/command/global.go +++ b/etcdctl/ctlv3/command/global.go @@ -19,6 +19,8 @@ import ( "errors" "io" "io/ioutil" + "log" + "os" "strings" "time" @@ -44,6 +46,8 @@ type GlobalFlags struct { IsHex bool User string + + Debug bool } type secureCfg struct { @@ -79,6 +83,14 @@ func initDisplayFromCmd(cmd *cobra.Command) { func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client { flags.SetPflagsFromEnv("ETCDCTL", cmd.InheritedFlags()) + debug, derr := cmd.Flags().GetBool("debug") + if derr != nil { + ExitWithError(ExitError, derr) + } + if debug { + clientv3.SetLogger(log.New(os.Stderr, "grpc: ", 0)) + } + endpoints, err := cmd.Flags().GetStringSlice("endpoints") if err != nil { ExitWithError(ExitError, err) diff --git a/etcdctl/ctlv3/ctl.go b/etcdctl/ctlv3/ctl.go index 33a77a748..92e715d97 100644 --- a/etcdctl/ctlv3/ctl.go +++ b/etcdctl/ctlv3/ctl.go @@ -44,6 +44,7 @@ var ( func init() { rootCmd.PersistentFlags().StringSliceVar(&globalFlags.Endpoints, "endpoints", []string{"127.0.0.1:2379"}, "gRPC endpoints") + rootCmd.PersistentFlags().BoolVar(&globalFlags.Debug, "debug", false, "enable client-side debug logging") rootCmd.PersistentFlags().StringVarP(&globalFlags.OutputFormat, "write-out", "w", "simple", "set the output format (fields, json, protobuf, simple, table)") rootCmd.PersistentFlags().BoolVar(&globalFlags.IsHex, "hex", false, "print byte strings as hex encoded strings")