@@ -117,7 +117,7 @@ type Options struct {
117117 DialerRetryTimeout time.Duration
118118
119119 // Optional logger for connection pool operations.
120- Logger internal.Logging
120+ Logger internal.LoggerWithLevel
121121}
122122
123123type lastDialErrorWrap struct {
@@ -226,7 +226,7 @@ func (p *ConnPool) checkMinIdleConns() {
226226 p .idleConnsLen .Add (- 1 )
227227
228228 p .freeTurn ()
229- p .logf (context .Background (), "addIdleConn panic: %+v" , err )
229+ p .logger (). Errorf (context .Background (), "addIdleConn panic: %+v" , err )
230230 }
231231 }()
232232
@@ -382,7 +382,7 @@ func (p *ConnPool) dialConn(ctx context.Context, pooled bool) (*Conn, error) {
382382 return cn , nil
383383 }
384384
385- p .logf (ctx , "redis: connection pool: failed to dial after %d attempts: %v" , maxRetries , lastErr )
385+ p .logger (). Errorf (ctx , "redis: connection pool: failed to dial after %d attempts: %v" , maxRetries , lastErr )
386386 // All retries failed - handle error tracking
387387 p .setLastDialError (lastErr )
388388 if atomic .AddUint32 (& p .dialErrorsNum , 1 ) == uint32 (p .cfg .PoolSize ) {
@@ -455,7 +455,7 @@ func (p *ConnPool) getConn(ctx context.Context) (*Conn, error) {
455455
456456 for {
457457 if attempts >= getAttempts {
458- p .logf (ctx , "redis: connection pool: was not able to get a healthy connection after %d attempts" , attempts )
458+ p .logger (). Errorf (ctx , "redis: connection pool: was not able to get a healthy connection after %d attempts" , attempts )
459459 break
460460 }
461461 attempts ++
@@ -482,12 +482,12 @@ func (p *ConnPool) getConn(ctx context.Context) (*Conn, error) {
482482 if hookManager != nil {
483483 acceptConn , err := hookManager .ProcessOnGet (ctx , cn , false )
484484 if err != nil {
485- p .logf (ctx , "redis: connection pool: failed to process idle connection by hook: %v" , err )
485+ p .logger (). Errorf (ctx , "redis: connection pool: failed to process idle connection by hook: %v" , err )
486486 _ = p .CloseConn (cn )
487487 continue
488488 }
489489 if ! acceptConn {
490- p .logf (ctx , "redis: connection pool: conn[%d] rejected by hook, returning to pool" , cn .GetID ())
490+ p .logger (). Errorf (ctx , "redis: connection pool: conn[%d] rejected by hook, returning to pool" , cn .GetID ())
491491 p .Put (ctx , cn )
492492 cn = nil
493493 continue
@@ -512,7 +512,7 @@ func (p *ConnPool) getConn(ctx context.Context) (*Conn, error) {
512512 // this should not happen with a new connection, but we handle it gracefully
513513 if err != nil || ! acceptConn {
514514 // Failed to process connection, discard it
515- p .logf (ctx , "redis: connection pool: failed to process new connection conn[%d] by hook: accept=%v, err=%v" , newcn .GetID (), acceptConn , err )
515+ p .logger (). Errorf (ctx , "redis: connection pool: failed to process new connection conn[%d] by hook: accept=%v, err=%v" , newcn .GetID (), acceptConn , err )
516516 _ = p .CloseConn (newcn )
517517 return nil , err
518518 }
@@ -706,7 +706,7 @@ func (p *ConnPool) popIdle() (*Conn, error) {
706706
707707 // If we exhausted all attempts without finding a usable connection, return nil
708708 if attempts > 1 && attempts >= maxAttempts && int32 (attempts ) >= p .poolSize .Load () {
709- p .logf (context .Background (), "redis: connection pool: failed to get a usable connection after %d attempts" , attempts )
709+ p .logger (). Errorf (context .Background (), "redis: connection pool: failed to get a usable connection after %d attempts" , attempts )
710710 return nil , nil
711711 }
712712
@@ -723,7 +723,7 @@ func (p *ConnPool) Put(ctx context.Context, cn *Conn) {
723723 // Peek at the reply type to check if it's a push notification
724724 if replyType , err := cn .PeekReplyTypeSafe (); err != nil || replyType != proto .RespPush {
725725 // Not a push notification or error peeking, remove connection
726- p .logf (ctx , "Conn has unread data (not push notification), removing it" )
726+ p .logger (). Errorf (ctx , "Conn has unread data (not push notification), removing it" )
727727 p .Remove (ctx , cn , err )
728728 }
729729 // It's a push notification, allow pooling (client will handle it)
@@ -736,7 +736,7 @@ func (p *ConnPool) Put(ctx context.Context, cn *Conn) {
736736 if hookManager != nil {
737737 shouldPool , shouldRemove , err = hookManager .ProcessOnPut (ctx , cn )
738738 if err != nil {
739- p .logf (ctx , "Connection hook error: %v" , err )
739+ p .logger (). Errorf (ctx , "Connection hook error: %v" , err )
740740 p .Remove (ctx , cn , err )
741741 return
742742 }
@@ -838,7 +838,7 @@ func (p *ConnPool) removeConn(cn *Conn) {
838838 // this can be idle conn
839839 for idx , ic := range p .idleConns {
840840 if ic .GetID () == cid {
841- p .logf (context .Background (), "redis: connection pool: removing idle conn[%d]" , cid )
841+ p .logger (). Errorf (context .Background (), "redis: connection pool: removing idle conn[%d]" , cid )
842842 p .idleConns = append (p .idleConns [:idx ], p .idleConns [idx + 1 :]... )
843843 p .idleConnsLen .Add (- 1 )
844844 break
@@ -954,7 +954,7 @@ func (p *ConnPool) isHealthyConn(cn *Conn, now time.Time) bool {
954954 if replyType , err := cn .rd .PeekReplyType (); err == nil && replyType == proto .RespPush {
955955 // For RESP3 connections with push notifications, we allow some buffered data
956956 // The client will process these notifications before using the connection
957- p .logf (context .Background (), "push: conn[%d] has buffered data, likely push notifications - will be processed by client" , cn .GetID ())
957+ p .logger (). Infof (context .Background (), "push: conn[%d] has buffered data, likely push notifications - will be processed by client" , cn .GetID ())
958958 return true // Connection is healthy, client will handle notifications
959959 }
960960 return false // Unexpected data, not push notifications, connection is unhealthy
@@ -965,10 +965,10 @@ func (p *ConnPool) isHealthyConn(cn *Conn, now time.Time) bool {
965965 return true
966966}
967967
968- func (p * ConnPool ) logf ( ctx context. Context , format string , args ... any ) {
968+ func (p * ConnPool ) logger () internal. LoggerWithLevel {
969969 if p .cfg .Logger != nil {
970- p .cfg .Logger .Printf (ctx , format , args ... )
971- } else {
972- internal .Logger .Printf (ctx , format , args ... )
970+ return p .cfg .Logger
973971 }
972+
973+ return & internal.LegacyLoggerAdapter {}
974974}
0 commit comments