forked from mirror/redis
Add prefix to package logger.
This commit is contained in:
parent
6dac5ea35c
commit
ebf51e1a1b
|
@ -255,13 +255,13 @@ func (c *ClusterClient) reloadSlots() {
|
||||||
|
|
||||||
client, err := c.randomClient()
|
client, err := c.randomClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Printf("redis: randomClient failed: %s", err)
|
Logger.Printf("randomClient failed: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
slots, err := client.ClusterSlots().Result()
|
slots, err := client.ClusterSlots().Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Printf("redis: ClusterSlots failed: %s", err)
|
Logger.Printf("ClusterSlots failed: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.setSlots(slots)
|
c.setSlots(slots)
|
||||||
|
|
|
@ -32,7 +32,7 @@ func usePrecise(dur time.Duration) bool {
|
||||||
func formatMs(dur time.Duration) string {
|
func formatMs(dur time.Duration) string {
|
||||||
if dur > 0 && dur < time.Millisecond {
|
if dur > 0 && dur < time.Millisecond {
|
||||||
Logger.Printf(
|
Logger.Printf(
|
||||||
"redis: specified duration is %s, but minimal supported value is %s",
|
"specified duration is %s, but minimal supported value is %s",
|
||||||
dur, time.Millisecond,
|
dur, time.Millisecond,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ func formatMs(dur time.Duration) string {
|
||||||
func formatSec(dur time.Duration) string {
|
func formatSec(dur time.Duration) string {
|
||||||
if dur > 0 && dur < time.Second {
|
if dur > 0 && dur < time.Second {
|
||||||
Logger.Printf(
|
Logger.Printf(
|
||||||
"redis: specified duration is %s, but minimal supported value is %s",
|
"specified duration is %s, but minimal supported value is %s",
|
||||||
dur, time.Second,
|
dur, time.Second,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
4
multi.go
4
multi.go
|
@ -52,7 +52,7 @@ func (c *Multi) putConn(cn *conn, err error) {
|
||||||
} else {
|
} else {
|
||||||
err := c.base.connPool.Put(cn)
|
err := c.base.connPool.Put(cn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Printf("redis: putConn failed: %s", err)
|
Logger.Printf("pool.Put failed: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ func (c *Multi) process(cmd Cmder) {
|
||||||
func (c *Multi) Close() error {
|
func (c *Multi) Close() error {
|
||||||
c.closed = true
|
c.closed = true
|
||||||
if err := c.Unwatch().Err(); err != nil {
|
if err := c.Unwatch().Err(); err != nil {
|
||||||
Logger.Printf("redis: Unwatch failed: %s", err)
|
Logger.Printf("Unwatch failed: %s", err)
|
||||||
}
|
}
|
||||||
return c.base.Close()
|
return c.base.Close()
|
||||||
}
|
}
|
||||||
|
|
6
pool.go
6
pool.go
|
@ -177,7 +177,7 @@ func (p *connPool) First() *conn {
|
||||||
var err error
|
var err error
|
||||||
cn, err = p.replace(cn)
|
cn, err = p.replace(cn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Printf("redis: replace failed: %s", err)
|
Logger.Printf("pool.replace failed: %s", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ func (p *connPool) wait() *conn {
|
||||||
var err error
|
var err error
|
||||||
cn, err = p.replace(cn)
|
cn, err = p.replace(cn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Printf("redis: replace failed: %s", err)
|
Logger.Printf("pool.replace failed: %s", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,7 +270,7 @@ func (p *connPool) Get() (cn *conn, isNew bool, err error) {
|
||||||
func (p *connPool) Put(cn *conn) error {
|
func (p *connPool) Put(cn *conn) error {
|
||||||
if cn.rd.Buffered() != 0 {
|
if cn.rd.Buffered() != 0 {
|
||||||
b, _ := cn.rd.Peek(cn.rd.Buffered())
|
b, _ := cn.rd.Peek(cn.rd.Buffered())
|
||||||
err := fmt.Errorf("redis: connection has unread data: %q", b)
|
err := fmt.Errorf("connection has unread data: %q", b)
|
||||||
Logger.Print(err)
|
Logger.Print(err)
|
||||||
return p.Remove(cn, err)
|
return p.Remove(cn, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,12 +238,12 @@ func (c *PubSub) reconnect(reason error) {
|
||||||
|
|
||||||
if len(c.channels) > 0 {
|
if len(c.channels) > 0 {
|
||||||
if err := c.Subscribe(c.channels...); err != nil {
|
if err := c.Subscribe(c.channels...); err != nil {
|
||||||
Logger.Printf("redis: Subscribe failed: %s", err)
|
Logger.Printf("Subscribe failed: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(c.patterns) > 0 {
|
if len(c.patterns) > 0 {
|
||||||
if err := c.PSubscribe(c.patterns...); err != nil {
|
if err := c.PSubscribe(c.patterns...); err != nil {
|
||||||
Logger.Printf("redis: PSubscribe failed: %s", err)
|
Logger.Printf("PSubscribe failed: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ func (c *PubSub) ReceiveMessage() (*Message, error) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
Logger.Printf("redis: PubSub.Ping failed: %s", err)
|
Logger.Printf("PubSub.Ping failed: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
redis.go
4
redis.go
|
@ -8,7 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Logger = log.New(os.Stderr, "", log.LstdFlags)
|
var Logger = log.New(os.Stderr, "redis: ", log.LstdFlags)
|
||||||
|
|
||||||
type baseClient struct {
|
type baseClient struct {
|
||||||
connPool pool
|
connPool pool
|
||||||
|
@ -30,7 +30,7 @@ func (c *baseClient) putConn(cn *conn, err error) {
|
||||||
err = c.connPool.Put(cn)
|
err = c.connPool.Put(cn)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Printf("redis: putConn failed: %s", err)
|
Logger.Printf("pool.Put failed: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
ring.go
2
ring.go
|
@ -201,7 +201,7 @@ func (ring *Ring) heartbeat() {
|
||||||
for _, shard := range ring.shards {
|
for _, shard := range ring.shards {
|
||||||
err := shard.Client.Ping().Err()
|
err := shard.Client.Ping().Err()
|
||||||
if shard.Vote(err == nil || err == errPoolTimeout) {
|
if shard.Vote(err == nil || err == errPoolTimeout) {
|
||||||
Logger.Printf("redis: ring shard state changed: %s", shard)
|
Logger.Printf("ring shard state changed: %s", shard)
|
||||||
rebalance = true
|
rebalance = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
30
sentinel.go
30
sentinel.go
|
@ -144,11 +144,11 @@ func (d *sentinelFailover) MasterAddr() (string, error) {
|
||||||
if d._sentinel != nil {
|
if d._sentinel != nil {
|
||||||
addr, err := d._sentinel.GetMasterAddrByName(d.masterName).Result()
|
addr, err := d._sentinel.GetMasterAddrByName(d.masterName).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Printf("redis-sentinel: GetMasterAddrByName %q failed: %s", d.masterName, err)
|
Logger.Printf("sentinel: GetMasterAddrByName %q failed: %s", d.masterName, err)
|
||||||
d.resetSentinel()
|
d.resetSentinel()
|
||||||
} else {
|
} else {
|
||||||
addr := net.JoinHostPort(addr[0], addr[1])
|
addr := net.JoinHostPort(addr[0], addr[1])
|
||||||
Logger.Printf("redis-sentinel: %q addr is %s", d.masterName, addr)
|
Logger.Printf("sentinel: %q addr is %s", d.masterName, addr)
|
||||||
return addr, nil
|
return addr, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ func (d *sentinelFailover) MasterAddr() (string, error) {
|
||||||
})
|
})
|
||||||
masterAddr, err := sentinel.GetMasterAddrByName(d.masterName).Result()
|
masterAddr, err := sentinel.GetMasterAddrByName(d.masterName).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Printf("redis-sentinel: GetMasterAddrByName %q failed: %s", d.masterName, err)
|
Logger.Printf("sentinel: GetMasterAddrByName %q failed: %s", d.masterName, err)
|
||||||
sentinel.Close()
|
sentinel.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ func (d *sentinelFailover) MasterAddr() (string, error) {
|
||||||
|
|
||||||
d.setSentinel(sentinel)
|
d.setSentinel(sentinel)
|
||||||
addr := net.JoinHostPort(masterAddr[0], masterAddr[1])
|
addr := net.JoinHostPort(masterAddr[0], masterAddr[1])
|
||||||
Logger.Printf("redis-sentinel: %q addr is %s", d.masterName, addr)
|
Logger.Printf("sentinel: %q addr is %s", d.masterName, addr)
|
||||||
return addr, nil
|
return addr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ func (d *sentinelFailover) setSentinel(sentinel *sentinelClient) {
|
||||||
func (d *sentinelFailover) discoverSentinels(sentinel *sentinelClient) {
|
func (d *sentinelFailover) discoverSentinels(sentinel *sentinelClient) {
|
||||||
sentinels, err := sentinel.Sentinels(d.masterName).Result()
|
sentinels, err := sentinel.Sentinels(d.masterName).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Printf("redis-sentinel: Sentinels %q failed: %s", d.masterName, err)
|
Logger.Printf("sentinel: Sentinels %q failed: %s", d.masterName, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, sentinel := range sentinels {
|
for _, sentinel := range sentinels {
|
||||||
|
@ -204,7 +204,7 @@ func (d *sentinelFailover) discoverSentinels(sentinel *sentinelClient) {
|
||||||
sentinelAddr := vals[i+1].(string)
|
sentinelAddr := vals[i+1].(string)
|
||||||
if !contains(d.sentinelAddrs, sentinelAddr) {
|
if !contains(d.sentinelAddrs, sentinelAddr) {
|
||||||
Logger.Printf(
|
Logger.Printf(
|
||||||
"redis-sentinel: discovered new %q sentinel: %s",
|
"sentinel: discovered new %q sentinel: %s",
|
||||||
d.masterName, sentinelAddr,
|
d.masterName, sentinelAddr,
|
||||||
)
|
)
|
||||||
d.sentinelAddrs = append(d.sentinelAddrs, sentinelAddr)
|
d.sentinelAddrs = append(d.sentinelAddrs, sentinelAddr)
|
||||||
|
@ -228,7 +228,7 @@ func (d *sentinelFailover) closeOldConns(newMaster string) {
|
||||||
}
|
}
|
||||||
if cn.RemoteAddr().String() != newMaster {
|
if cn.RemoteAddr().String() != newMaster {
|
||||||
err := fmt.Errorf(
|
err := fmt.Errorf(
|
||||||
"redis-sentinel: closing connection to the old master %s",
|
"sentinel: closing connection to the old master %s",
|
||||||
cn.RemoteAddr(),
|
cn.RemoteAddr(),
|
||||||
)
|
)
|
||||||
Logger.Print(err)
|
Logger.Print(err)
|
||||||
|
@ -249,7 +249,7 @@ func (d *sentinelFailover) listen() {
|
||||||
if pubsub == nil {
|
if pubsub == nil {
|
||||||
pubsub = d._sentinel.PubSub()
|
pubsub = d._sentinel.PubSub()
|
||||||
if err := pubsub.Subscribe("+switch-master"); err != nil {
|
if err := pubsub.Subscribe("+switch-master"); err != nil {
|
||||||
Logger.Printf("redis-sentinel: Subscribe failed: %s", err)
|
Logger.Printf("sentinel: Subscribe failed: %s", err)
|
||||||
d.lock.Lock()
|
d.lock.Lock()
|
||||||
d.resetSentinel()
|
d.resetSentinel()
|
||||||
d.lock.Unlock()
|
d.lock.Unlock()
|
||||||
|
@ -257,36 +257,36 @@ func (d *sentinelFailover) listen() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
msgIface, err := pubsub.Receive()
|
msg, err := pubsub.Receive()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Printf("redis-sentinel: Receive failed: %s", err)
|
Logger.Printf("sentinel: Receive failed: %s", err)
|
||||||
pubsub.Close()
|
pubsub.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch msg := msgIface.(type) {
|
switch msg := msg.(type) {
|
||||||
case *Message:
|
case *Message:
|
||||||
switch msg.Channel {
|
switch msg.Channel {
|
||||||
case "+switch-master":
|
case "+switch-master":
|
||||||
parts := strings.Split(msg.Payload, " ")
|
parts := strings.Split(msg.Payload, " ")
|
||||||
if parts[0] != d.masterName {
|
if parts[0] != d.masterName {
|
||||||
Logger.Printf("redis-sentinel: ignore new %s addr", parts[0])
|
Logger.Printf("sentinel: ignore new %s addr", parts[0])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
addr := net.JoinHostPort(parts[3], parts[4])
|
addr := net.JoinHostPort(parts[3], parts[4])
|
||||||
Logger.Printf(
|
Logger.Printf(
|
||||||
"redis-sentinel: new %q addr is %s",
|
"sentinel: new %q addr is %s",
|
||||||
d.masterName, addr,
|
d.masterName, addr,
|
||||||
)
|
)
|
||||||
|
|
||||||
d.closeOldConns(addr)
|
d.closeOldConns(addr)
|
||||||
default:
|
default:
|
||||||
Logger.Printf("redis-sentinel: unsupported message: %s", msg)
|
Logger.Printf("sentinel: unsupported message: %s", msg)
|
||||||
}
|
}
|
||||||
case *Subscription:
|
case *Subscription:
|
||||||
// Ignore.
|
// Ignore.
|
||||||
default:
|
default:
|
||||||
Logger.Printf("redis-sentinel: unsupported message: %s", msgIface)
|
Logger.Printf("sentinel: unsupported message: %s", msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue