From 38364356390134c823c130b8ad3d19a8ca24c602 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Thu, 31 Jul 2014 16:01:54 +0300 Subject: [PATCH] Remove glog. --- .travis.yml | 1 - pool.go | 8 ++++---- redis.go | 7 +++---- sentinel.go | 33 ++++++++++++++++----------------- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0b3f817..c3cf4b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ go: - tip install: - - go get github.com/golang/glog - go get gopkg.in/bufio.v1 - go get gopkg.in/check.v1 - mkdir -p $HOME/gopath/src/gopkg.in diff --git a/pool.go b/pool.go index fed110d..7031a45 100644 --- a/pool.go +++ b/pool.go @@ -3,11 +3,11 @@ package redis import ( "container/list" "errors" + "log" "net" "sync" "time" - "github.com/golang/glog" "gopkg.in/bufio.v1" ) @@ -139,7 +139,7 @@ func (p *connPool) Get() (*conn, bool, error) { } if time.Since(cn.usedAt) > p.opt.IdleTimeout { if err := p.remove(cn); err != nil { - glog.Errorf("remove failed: %s", err) + log.Printf("remove failed: %s", err) } } } @@ -183,7 +183,7 @@ func (p *connPool) Get() (*conn, bool, error) { func (p *connPool) Put(cn *conn) error { if cn.rd.Buffered() != 0 { b, _ := cn.rd.ReadN(cn.rd.Buffered()) - glog.Errorf("redis: connection has unread data: %q", b) + log.Printf("redis: connection has unread data: %q", b) return p.Remove(cn) } @@ -267,7 +267,7 @@ func (p *connPool) Close() error { break } if err := p.remove(e.Value.(*conn)); err != nil { - glog.Errorf("cn.Close failed: %s", err) + log.Printf("cn.Close failed: %s", err) retErr = err } } diff --git a/redis.go b/redis.go index 6c64225..ffed085 100644 --- a/redis.go +++ b/redis.go @@ -1,10 +1,9 @@ package redis import ( + "log" "net" "time" - - "github.com/golang/glog" ) type baseClient struct { @@ -82,13 +81,13 @@ func (c *baseClient) freeConn(cn *conn, ei error) error { func (c *baseClient) removeConn(cn *conn) { if err := c.connPool.Remove(cn); err != nil { - glog.Errorf("pool.Remove failed: %s", err) + log.Printf("pool.Remove failed: %s", err) } } func (c *baseClient) putConn(cn *conn) { if err := c.connPool.Put(cn); err != nil { - glog.Errorf("pool.Put failed: %s", err) + log.Printf("pool.Put failed: %s", err) } } diff --git a/sentinel.go b/sentinel.go index 6b22245..262ac44 100644 --- a/sentinel.go +++ b/sentinel.go @@ -2,12 +2,11 @@ package redis import ( "errors" + "log" "net" "strings" "sync" "time" - - "github.com/golang/glog" ) //------------------------------------------------------------------------------ @@ -149,11 +148,11 @@ func (d *sentinelFailover) MasterAddr() (string, error) { if d._sentinel != nil { addr, err := d._sentinel.GetMasterAddrByName(d.masterName).Result() if err != nil { - glog.Errorf("redis-sentinel: GetMasterAddrByName %s failed: %s", d.masterName, err) + log.Printf("redis-sentinel: GetMasterAddrByName %q failed: %s", d.masterName, err) d.resetSentinel() } else { addr := net.JoinHostPort(addr[0], addr[1]) - glog.Infof("redis-sentinel: %s addr is %s", d.masterName, addr) + log.Printf("redis-sentinel: %q addr is %s", d.masterName, addr) return addr, nil } } @@ -174,14 +173,14 @@ func (d *sentinelFailover) MasterAddr() (string, error) { }) addr, err := sentinel.GetMasterAddrByName(d.masterName).Result() if err != nil { - glog.Errorf("redis-sentinel: GetMasterAddrByName %s failed: %s", d.masterName, err) + log.Printf("redis-sentinel: GetMasterAddrByName %q failed: %s", d.masterName, err) } else { // Push working sentinel to the top. d.sentinelAddrs[0], d.sentinelAddrs[i] = d.sentinelAddrs[i], d.sentinelAddrs[0] d.setSentinel(sentinel) addr := net.JoinHostPort(addr[0], addr[1]) - glog.Infof("redis-sentinel: %s addr is %s", d.masterName, addr) + log.Printf("redis-sentinel: %q addr is %s", d.masterName, addr) return addr, nil } } @@ -198,7 +197,7 @@ func (d *sentinelFailover) setSentinel(sentinel *sentinelClient) { func (d *sentinelFailover) discoverSentinels(sentinel *sentinelClient) { sentinels, err := sentinel.Sentinels(d.masterName).Result() if err != nil { - glog.Errorf("redis-sentinel: Sentinels %s failed: %s", d.masterName, err) + log.Printf("redis-sentinel: Sentinels %q failed: %s", d.masterName, err) return } for _, sentinel := range sentinels { @@ -208,8 +207,8 @@ func (d *sentinelFailover) discoverSentinels(sentinel *sentinelClient) { if key == "name" { sentinelAddr := vals[i+1].(string) if !contains(d.sentinelAddrs, sentinelAddr) { - glog.Infof( - "redis-sentinel: discovered new sentinel for %s: %s", + log.Printf( + "redis-sentinel: discovered new %q sentinel: %s", d.masterName, sentinelAddr, ) d.sentinelAddrs = append(d.sentinelAddrs, sentinelAddr) @@ -225,7 +224,7 @@ func (d *sentinelFailover) listen() { if pubsub == nil { pubsub = d._sentinel.PubSub() if err := pubsub.Subscribe("+switch-master"); err != nil { - glog.Errorf("redis-sentinel: Subscribe failed: %s", err) + log.Printf("redis-sentinel: Subscribe failed: %s", err) d.lock.Lock() d.resetSentinel() d.lock.Unlock() @@ -235,7 +234,7 @@ func (d *sentinelFailover) listen() { msgIface, err := pubsub.Receive() if err != nil { - glog.Errorf("redis-sentinel: Receive failed: %s", err) + log.Printf("redis-sentinel: Receive failed: %s", err) pubsub = nil return } @@ -246,17 +245,17 @@ func (d *sentinelFailover) listen() { case "+switch-master": parts := strings.Split(msg.Payload, " ") if parts[0] != d.masterName { - glog.Errorf("redis-sentinel: ignore new %s addr", parts[0]) + log.Printf("redis-sentinel: ignore new %s addr", parts[0]) continue } addr := net.JoinHostPort(parts[3], parts[4]) - glog.Infof( - "redis-sentinel: new %s addr is %s", + log.Printf( + "redis-sentinel: new %q addr is %s", d.masterName, addr, ) d.pool.Filter(func(cn *conn) bool { if cn.RemoteAddr().String() != addr { - glog.Infof( + log.Printf( "redis-sentinel: closing connection to old master %s", cn.RemoteAddr(), ) @@ -265,12 +264,12 @@ func (d *sentinelFailover) listen() { return true }) default: - glog.Errorf("redis-sentinel: unsupported message: %s", msg) + log.Printf("redis-sentinel: unsupported message: %s", msg) } case *Subscription: // Ignore. default: - glog.Errorf("redis-sentinel: unsupported message: %s", msgIface) + log.Printf("redis-sentinel: unsupported message: %s", msgIface) } } }