From 5af902d026bf8b425a4d43c5b8687b8ac5905f65 Mon Sep 17 00:00:00 2001 From: Alain Jobart Date: Mon, 27 Jan 2014 11:59:14 -0800 Subject: [PATCH 1/2] Switching a few more places to glog. --- go/cmd/vtclient2/vtclient2.go | 12 +++++------ go/cmd/zk/zkcmd.go | 38 +++++++++++++++------------------ go/cmd/zkclient2/zkclient2.go | 2 +- go/vt/client2/tablet/tclient.go | 4 ++-- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/go/cmd/vtclient2/vtclient2.go b/go/cmd/vtclient2/vtclient2.go index 941266abae..e561cee511 100644 --- a/go/cmd/vtclient2/vtclient2.go +++ b/go/cmd/vtclient2/vtclient2.go @@ -8,11 +8,11 @@ import ( "encoding/json" "flag" "fmt" - "log" "os" "strings" "time" + log "github.com/golang/glog" "github.com/youtube/vitess/go/db" _ "github.com/youtube/vitess/go/vt/client2" _ "github.com/youtube/vitess/go/vt/client2/tablet" @@ -105,7 +105,7 @@ func main() { log.Fatalf("client error: %v", err) } - log.Println("Sending the query...") + log.Infof("Sending the query...") now := time.Now() // handle dml @@ -126,7 +126,7 @@ func main() { } n, err := r.RowsAffected() - log.Println("Total time:", time.Now().Sub(now), "Rows affected:", n) + log.Infof("Total time:", time.Now().Sub(now), "Rows affected:", n) } else { // launch the query @@ -147,7 +147,7 @@ func main() { for _, field := range cols { line += "\t" + field } - log.Println(line) + log.Infof(line) } // get the rows @@ -168,13 +168,13 @@ func main() { line += "\t" } } - log.Println(line) + log.Infof(line) } rowIndex++ } if err := r.Err(); err != nil { log.Fatalf("Error %v\n", err) } - log.Println("Total time:", time.Now().Sub(now), "Row count:", rowIndex) + log.Infof("Total time:", time.Now().Sub(now), "Row count:", rowIndex) } } diff --git a/go/cmd/zk/zkcmd.go b/go/cmd/zk/zkcmd.go index 553538821c..a645459187 100644 --- a/go/cmd/zk/zkcmd.go +++ b/go/cmd/zk/zkcmd.go @@ -4,7 +4,6 @@ import ( "archive/zip" "fmt" "io/ioutil" - "log" "os" "os/exec" "os/signal" @@ -16,6 +15,7 @@ import ( "time" opts "code.google.com/p/opts-go" + log "github.com/golang/glog" "github.com/youtube/vitess/go/terminal" "github.com/youtube/vitess/go/zk" @@ -131,7 +131,6 @@ func init() { "watch": cmdWatch, "zip": cmdZip, } - log.SetFlags(0) zconn = zk.NewMetaConn(false) } @@ -259,7 +258,7 @@ func cmdElock(args []string) { zconn.Delete(zkPath, -1) return case event := <-watch: - log.Printf("elock: event %v: %v", zkPath, event) + log.Infof("elock: event %v: %v", zkPath, event) if !event.Ok() { //log.Fatalf("elock: error %v: %v", zkPath, event) break watchLoop @@ -293,13 +292,13 @@ func cmdWatch(args []string) { case <-sigRecv: return case event := <-eventChan: - log.Printf("watch: event %v: %v", event.Path, event) + log.Infof("watch: event %v: %v", event.Path, event) if event.Type == zookeeper.EVENT_CHANGED { data, stat, watch, err := zconn.GetW(event.Path) if err != nil { log.Fatalf("ERROR: failed to watch %v", err) } - log.Printf("watch: %v %v\n", event.Path, stat) + log.Infof("watch: %v %v\n", event.Path, stat) println(data) go func() { eventChan <- <-watch @@ -307,7 +306,7 @@ func cmdWatch(args []string) { } else if event.State == zookeeper.STATE_CLOSED { return } else if event.Type == zookeeper.EVENT_DELETED { - log.Printf("watch: %v deleted\n", event.Path) + log.Infof("watch: %v deleted\n", event.Path) } else { // Most likely a session event - try t _, _, watch, err := zconn.GetW(event.Path) @@ -358,7 +357,7 @@ func cmdLs(args []string) { if err != nil { hasError = true if !*force || !zookeeper.IsError(err, zookeeper.ZNONODE) { - log.Printf("ls: cannot access %v: %v", zkPath, err) + log.Warningf("ls: cannot access %v: %v", zkPath, err) } } @@ -384,7 +383,7 @@ func cmdLs(args []string) { stat, err := zconn.Exists(localPath) if err != nil { if !*force || !zookeeper.IsError(err, zookeeper.ZNONODE) { - log.Printf("ls: cannot access: %v: %v", localPath, err) + log.Warningf("ls: cannot access: %v: %v", localPath, err) } } else { stats[i] = stat @@ -521,7 +520,7 @@ func cmdRm(args []string) { if err != nil { if !*force || !zookeeper.IsError(err, zookeeper.ZNONODE) { hasError = true - log.Printf("rm: cannot delete %v: %v", zkPath, err) + log.Warningf("rm: cannot delete %v: %v", zkPath, err) } } } @@ -552,7 +551,7 @@ func cmdCat(args []string) { if err != nil { hasError = true if !*force || !zookeeper.IsError(err, zookeeper.ZNONODE) { - log.Printf("cat: cannot access %v: %v", zkPath, err) + log.Warningf("cat: cannot access %v: %v", zkPath, err) } } else { if *longListing { @@ -578,7 +577,7 @@ func cmdEdit(args []string) { data, stat, err := zconn.Get(zkPath) if err != nil { if !*force || !zookeeper.IsError(err, zookeeper.ZNONODE) { - log.Printf("edit: cannot access %v: %v", zkPath, err) + log.Warningf("edit: cannot access %v: %v", zkPath, err) } os.Exit(1) } @@ -591,7 +590,7 @@ func cmdEdit(args []string) { f.Close() } if err != nil { - log.Printf("edit: cannot write file %v", err) + log.Warningf("edit: cannot write file %v", err) os.Exit(1) } @@ -602,15 +601,13 @@ func cmdEdit(args []string) { err = cmd.Run() if err != nil { os.Remove(tmpPath) - log.Printf("edit: cannot start $EDITOR: %v", err) - os.Exit(1) + log.Fatalf("edit: cannot start $EDITOR: %v", err) } fileData, err := ioutil.ReadFile(tmpPath) if err != nil { os.Remove(tmpPath) - log.Printf("edit: cannot read file %v", err) - os.Exit(1) + log.Fatalf("edit: cannot read file %v", err) } if string(fileData) != data { @@ -618,8 +615,7 @@ func cmdEdit(args []string) { _, err = zconn.Set(zkPath, string(fileData), stat.Version()) if err != nil { os.Remove(tmpPath) - log.Printf("edit: cannot write zk file %v", err) - os.Exit(1) + log.Fatalf("edit: cannot write zk file %v", err) } } os.Remove(tmpPath) @@ -648,7 +644,7 @@ func cmdStat(args []string) { if err != nil { hasError = true if !*force || !zookeeper.IsError(err, zookeeper.ZNONODE) { - log.Printf("stat: cannot access %v: %v", zkPath, err) + log.Warningf("stat: cannot access %v: %v", zkPath, err) } continue } @@ -735,7 +731,7 @@ func cmdChmod(args []string) { aclv, _, err := zconn.ACL(zkPath) if err != nil { hasError = true - log.Printf("chmod: cannot set access %v: %v", zkPath, err) + log.Warningf("chmod: cannot set access %v: %v", zkPath, err) continue } if addPerms { @@ -746,7 +742,7 @@ func cmdChmod(args []string) { err = zconn.SetACL(zkPath, aclv, -1) if err != nil { hasError = true - log.Printf("chmod: cannot set access %v: %v", zkPath, err) + log.Warningf("chmod: cannot set access %v: %v", zkPath, err) continue } } diff --git a/go/cmd/zkclient2/zkclient2.go b/go/cmd/zkclient2/zkclient2.go index 2b0dc9e252..ae38951546 100644 --- a/go/cmd/zkclient2/zkclient2.go +++ b/go/cmd/zkclient2/zkclient2.go @@ -7,11 +7,11 @@ package main import ( "flag" "fmt" - "log" "os" "sort" "time" + log "github.com/golang/glog" "github.com/youtube/vitess/go/rpcplus" "github.com/youtube/vitess/go/rpcwrap/bsonrpc" "github.com/youtube/vitess/go/sync2" diff --git a/go/vt/client2/tablet/tclient.go b/go/vt/client2/tablet/tclient.go index 11d2efaf01..668836755b 100644 --- a/go/vt/client2/tablet/tclient.go +++ b/go/vt/client2/tablet/tclient.go @@ -11,10 +11,10 @@ package tablet import ( "errors" "fmt" - "log" "net/url" "strings" + log "github.com/golang/glog" "github.com/youtube/vitess/go/db" mproto "github.com/youtube/vitess/go/mysql/proto" "github.com/youtube/vitess/go/rpcplus" @@ -315,7 +315,7 @@ func (sr *StreamResult) Next() (row []interface{}) { qr, ok := <-sr.sr if !ok { if sr.call.Error != nil { - log.Printf("vt: error reading the next value %v", sr.call.Error.Error()) + log.Warningf("vt: error reading the next value %v", sr.call.Error.Error()) sr.err = sr.call.Error } return nil From a64f1a634ff57f3902770cfc75bd10249d898245 Mon Sep 17 00:00:00 2001 From: Alain Jobart Date: Mon, 27 Jan 2014 12:03:20 -0800 Subject: [PATCH 2/2] Fixing tests in here. --- go/vt/binlog/binlog_streamer_test.go | 2 +- go/vt/binlog/event_streamer_test.go | 2 +- go/vt/binlog/keyrange_filter_test.go | 2 +- go/vt/binlog/mysqlbinlog_test.go | 4 ++-- go/vt/binlog/tables_filter_test.go | 4 +--- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/go/vt/binlog/binlog_streamer_test.go b/go/vt/binlog/binlog_streamer_test.go index 9a828a0996..e822504e9f 100644 --- a/go/vt/binlog/binlog_streamer_test.go +++ b/go/vt/binlog/binlog_streamer_test.go @@ -16,7 +16,7 @@ import ( "github.com/youtube/vitess/go/sync2" "github.com/youtube/vitess/go/testfiles" - "github.com/youtube/vitess/go/vt/mysqlctl/proto" + "github.com/youtube/vitess/go/vt/binlog/proto" ) func TestPosParse(t *testing.T) { diff --git a/go/vt/binlog/event_streamer_test.go b/go/vt/binlog/event_streamer_test.go index cc4125bcb1..ee9b75a734 100644 --- a/go/vt/binlog/event_streamer_test.go +++ b/go/vt/binlog/event_streamer_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/youtube/vitess/go/vt/mysqlctl/proto" + "github.com/youtube/vitess/go/vt/binlog/proto" ) type eventErrorCase struct { diff --git a/go/vt/binlog/keyrange_filter_test.go b/go/vt/binlog/keyrange_filter_test.go index 2e4e392655..33e2226a64 100644 --- a/go/vt/binlog/keyrange_filter_test.go +++ b/go/vt/binlog/keyrange_filter_test.go @@ -8,8 +8,8 @@ import ( "fmt" "testing" + "github.com/youtube/vitess/go/vt/binlog/proto" "github.com/youtube/vitess/go/vt/key" - "github.com/youtube/vitess/go/vt/mysqlctl/proto" ) var testKeyRange = key.KeyRange{ diff --git a/go/vt/binlog/mysqlbinlog_test.go b/go/vt/binlog/mysqlbinlog_test.go index 908ec404a4..d7bc0fd892 100644 --- a/go/vt/binlog/mysqlbinlog_test.go +++ b/go/vt/binlog/mysqlbinlog_test.go @@ -112,7 +112,7 @@ func TestWarning(t *testing.T) { ioutil.ReadAll(out) mbl.Wait() logutil.Flush() - warnbytes, err := ioutil.ReadFile(path.Join(os.TempDir(), "mysqlctl.test.WARNING")) + warnbytes, err := ioutil.ReadFile(path.Join(os.TempDir(), "binlog.test.WARNING")) if err != nil { t.Error(err) } @@ -135,7 +135,7 @@ func TestError(t *testing.T) { ioutil.ReadAll(out) mbl.Wait() logutil.Flush() - warnbytes, err := ioutil.ReadFile(path.Join(os.TempDir(), "mysqlctl.test.ERROR")) + warnbytes, err := ioutil.ReadFile(path.Join(os.TempDir(), "binlog.test.ERROR")) if err != nil { t.Error(err) } diff --git a/go/vt/binlog/tables_filter_test.go b/go/vt/binlog/tables_filter_test.go index 08c1a90324..43d6ab2f8a 100644 --- a/go/vt/binlog/tables_filter_test.go +++ b/go/vt/binlog/tables_filter_test.go @@ -5,11 +5,9 @@ package binlog import ( - //"fmt" "testing" - // "github.com/youtube/vitess/go/vt/key" - "github.com/youtube/vitess/go/vt/mysqlctl/proto" + "github.com/youtube/vitess/go/vt/binlog/proto" ) var testTables = []string{