mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
Log with context to associate all log by traceID (#1413)
* Log with context to associate all log by traceID
This commit is contained in:
16
pubsub.go
16
pubsub.go
@ -162,7 +162,7 @@ func (c *PubSub) closeTheCn(reason error) error {
|
||||
return nil
|
||||
}
|
||||
if !c.closed {
|
||||
internal.Logger.Printf("redis: discarding bad PubSub connection: %s", reason)
|
||||
internal.Logger.Printf(c.getContext(), "redis: discarding bad PubSub connection: %s", reason)
|
||||
}
|
||||
err := c.closeConn(c.cn)
|
||||
c.cn = nil
|
||||
@ -450,6 +450,14 @@ func (c *PubSub) ChannelWithSubscriptions(ctx context.Context, size int) <-chan
|
||||
return c.allCh
|
||||
}
|
||||
|
||||
func (c *PubSub) getContext() context.Context {
|
||||
if c.cmd != nil {
|
||||
return c.cmd.ctx
|
||||
}
|
||||
|
||||
return context.Background()
|
||||
}
|
||||
|
||||
func (c *PubSub) initPing() {
|
||||
ctx := context.TODO()
|
||||
c.ping = make(chan struct{}, 1)
|
||||
@ -531,10 +539,11 @@ func (c *PubSub) initMsgChan(size int) {
|
||||
}
|
||||
case <-timer.C:
|
||||
internal.Logger.Printf(
|
||||
c.getContext(),
|
||||
"redis: %s channel is full for %s (message is dropped)", c, pingTimeout)
|
||||
}
|
||||
default:
|
||||
internal.Logger.Printf("redis: unknown message type: %T", msg)
|
||||
internal.Logger.Printf(c.getContext(), "redis: unknown message type: %T", msg)
|
||||
}
|
||||
}
|
||||
}()
|
||||
@ -579,7 +588,7 @@ func (c *PubSub) initAllChan(size int) {
|
||||
case *Message:
|
||||
c.sendMessage(msg, timer)
|
||||
default:
|
||||
internal.Logger.Printf("redis: unknown message type: %T", msg)
|
||||
internal.Logger.Printf(c.getContext(), "redis: unknown message type: %T", msg)
|
||||
}
|
||||
}
|
||||
}()
|
||||
@ -594,6 +603,7 @@ func (c *PubSub) sendMessage(msg interface{}, timer *time.Timer) {
|
||||
}
|
||||
case <-timer.C:
|
||||
internal.Logger.Printf(
|
||||
c.getContext(),
|
||||
"redis: %s channel is full for %s (message is dropped)", c, pingTimeout)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user