@@ -121,7 +121,7 @@ func (hwm *handoffWorkerManager) onDemandWorker() {
121121 defer func () {
122122 // Handle panics to ensure proper cleanup
123123 if r := recover (); r != nil {
124- internal . Logger . Printf (context .Background (), logs .WorkerPanicRecovered (r ))
124+ hwm . logf (context .Background (), logs .WorkerPanicRecovered (r ))
125125 }
126126
127127 // Decrement active worker count when exiting
@@ -146,21 +146,21 @@ func (hwm *handoffWorkerManager) onDemandWorker() {
146146 select {
147147 case <- hwm .shutdown :
148148 if internal .LogLevel .InfoOrAbove () {
149- internal . Logger . Printf (context .Background (), logs .WorkerExitingDueToShutdown ())
149+ hwm . logf (context .Background (), logs .WorkerExitingDueToShutdown ())
150150 }
151151 return
152152 case <- timer .C :
153153 // Worker has been idle for too long, exit to save resources
154154 if internal .LogLevel .InfoOrAbove () {
155- internal . Logger . Printf (context .Background (), logs .WorkerExitingDueToInactivityTimeout (hwm .workerTimeout ))
155+ hwm . logf (context .Background (), logs .WorkerExitingDueToInactivityTimeout (hwm .workerTimeout ))
156156 }
157157 return
158158 case request := <- hwm .handoffQueue :
159159 // Check for shutdown before processing
160160 select {
161161 case <- hwm .shutdown :
162162 if internal .LogLevel .InfoOrAbove () {
163- internal . Logger . Printf (context .Background (), logs .WorkerExitingDueToShutdownWhileProcessing ())
163+ hwm . logf (context .Background (), logs .WorkerExitingDueToShutdownWhileProcessing ())
164164 }
165165 // Clean up the request before exiting
166166 hwm .pending .Delete (request .ConnID )
@@ -178,7 +178,7 @@ func (hwm *handoffWorkerManager) processHandoffRequest(request HandoffRequest) {
178178 // Remove from pending map
179179 defer hwm .pending .Delete (request .Conn .GetID ())
180180 if internal .LogLevel .InfoOrAbove () {
181- internal . Logger . Printf (context .Background (), logs .HandoffStarted (request .Conn .GetID (), request .Endpoint ))
181+ hwm . logf (context .Background (), logs .HandoffStarted (request .Conn .GetID (), request .Endpoint ))
182182 }
183183
184184 // Create a context with handoff timeout from config
@@ -226,12 +226,12 @@ func (hwm *handoffWorkerManager) processHandoffRequest(request HandoffRequest) {
226226 if hwm .config != nil {
227227 maxRetries = hwm .config .MaxHandoffRetries
228228 }
229- internal . Logger . Printf (context .Background (), logs .HandoffFailed (request .ConnID , request .Endpoint , currentRetries , maxRetries , err ))
229+ hwm . logf (context .Background (), logs .HandoffFailed (request .ConnID , request .Endpoint , currentRetries , maxRetries , err ))
230230 }
231231 time .AfterFunc (afterTime , func () {
232232 if err := hwm .queueHandoff (request .Conn ); err != nil {
233233 if internal .LogLevel .WarnOrAbove () {
234- internal . Logger . Printf (context .Background (), logs .CannotQueueHandoffForRetry (err ))
234+ hwm . logf (context .Background (), logs .CannotQueueHandoffForRetry (err ))
235235 }
236236 hwm .closeConnFromRequest (context .Background (), request , err )
237237 }
@@ -259,7 +259,7 @@ func (hwm *handoffWorkerManager) queueHandoff(conn *pool.Conn) error {
259259 // if shouldHandoff is false and retries is 0, then we are not retrying and not do a handoff
260260 if ! shouldHandoff && conn .HandoffRetries () == 0 {
261261 if internal .LogLevel .InfoOrAbove () {
262- internal . Logger . Printf (context .Background (), logs .ConnectionNotMarkedForHandoff (conn .GetID ()))
262+ hwm . logf (context .Background (), logs .ConnectionNotMarkedForHandoff (conn .GetID ()))
263263 }
264264 return errors .New (logs .ConnectionNotMarkedForHandoffError (conn .GetID ()))
265265 }
@@ -302,7 +302,7 @@ func (hwm *handoffWorkerManager) queueHandoff(conn *pool.Conn) error {
302302 queueLen := len (hwm .handoffQueue )
303303 queueCap := cap (hwm .handoffQueue )
304304 if internal .LogLevel .WarnOrAbove () {
305- internal . Logger . Printf (context .Background (), logs .HandoffQueueFull (queueLen , queueCap ))
305+ hwm . logf (context .Background (), logs .HandoffQueueFull (queueLen , queueCap ))
306306 }
307307 }
308308 }
@@ -356,7 +356,7 @@ func (hwm *handoffWorkerManager) performConnectionHandoff(ctx context.Context, c
356356
357357 // Check if circuit breaker is open before attempting handoff
358358 if circuitBreaker .IsOpen () {
359- internal . Logger . Printf (ctx , logs .CircuitBreakerOpen (connID , newEndpoint ))
359+ hwm . logf (ctx , logs .CircuitBreakerOpen (connID , newEndpoint ))
360360 return false , ErrCircuitBreakerOpen // Don't retry when circuit breaker is open
361361 }
362362
@@ -385,15 +385,15 @@ func (hwm *handoffWorkerManager) performHandoffInternal(
385385 connID uint64 ,
386386) (shouldRetry bool , err error ) {
387387 retries := conn .IncrementAndGetHandoffRetries (1 )
388- internal . Logger . Printf (ctx , logs .HandoffRetryAttempt (connID , retries , newEndpoint , conn .RemoteAddr ().String ()))
388+ hwm . logf (ctx , logs .HandoffRetryAttempt (connID , retries , newEndpoint , conn .RemoteAddr ().String ()))
389389 maxRetries := 3 // Default fallback
390390 if hwm .config != nil {
391391 maxRetries = hwm .config .MaxHandoffRetries
392392 }
393393
394394 if retries > maxRetries {
395395 if internal .LogLevel .WarnOrAbove () {
396- internal . Logger . Printf (ctx , logs .ReachedMaxHandoffRetries (connID , newEndpoint , maxRetries ))
396+ hwm . logf (ctx , logs .ReachedMaxHandoffRetries (connID , newEndpoint , maxRetries ))
397397 }
398398 // won't retry on ErrMaxHandoffRetriesReached
399399 return false , ErrMaxHandoffRetriesReached
@@ -405,7 +405,7 @@ func (hwm *handoffWorkerManager) performHandoffInternal(
405405 // Create new connection to the new endpoint
406406 newNetConn , err := endpointDialer (ctx )
407407 if err != nil {
408- internal . Logger . Printf (ctx , logs .FailedToDialNewEndpoint (connID , newEndpoint , err ))
408+ hwm . logf (ctx , logs .FailedToDialNewEndpoint (connID , newEndpoint , err ))
409409 // will retry
410410 // Maybe a network error - retry after a delay
411411 return true , err
@@ -425,7 +425,7 @@ func (hwm *handoffWorkerManager) performHandoffInternal(
425425 conn .SetRelaxedTimeoutWithDeadline (relaxedTimeout , relaxedTimeout , deadline )
426426
427427 if internal .LogLevel .InfoOrAbove () {
428- internal . Logger . Printf (context .Background (), logs .ApplyingRelaxedTimeoutDueToPostHandoff (connID , relaxedTimeout , deadline .Format ("15:04:05.000" )))
428+ hwm . logf (context .Background (), logs .ApplyingRelaxedTimeoutDueToPostHandoff (connID , relaxedTimeout , deadline .Format ("15:04:05.000" )))
429429 }
430430 }
431431
@@ -447,7 +447,7 @@ func (hwm *handoffWorkerManager) performHandoffInternal(
447447 // - clear the handoff state (shouldHandoff, endpoint, seqID)
448448 // - reset the handoff retries to 0
449449 conn .ClearHandoffState ()
450- internal . Logger . Printf (ctx , logs .HandoffSucceeded (connID , newEndpoint ))
450+ hwm . logf (ctx , logs .HandoffSucceeded (connID , newEndpoint ))
451451
452452 // successfully completed the handoff, no retry needed and no error
453453 return false , nil
@@ -478,15 +478,23 @@ func (hwm *handoffWorkerManager) closeConnFromRequest(ctx context.Context, reque
478478 if pooler != nil {
479479 pooler .Remove (ctx , conn , err )
480480 if internal .LogLevel .WarnOrAbove () {
481- internal . Logger . Printf (ctx , logs .RemovingConnectionFromPool (conn .GetID (), err ))
481+ hwm . logf (ctx , logs .RemovingConnectionFromPool (conn .GetID (), err ))
482482 }
483483 } else {
484484 err := conn .Close () // Close the connection if no pool provided
485485 if err != nil {
486- internal . Logger . Printf (ctx , "redis: failed to close connection: %v" , err )
486+ hwm . logf (ctx , "redis: failed to close connection: %v" , err )
487487 }
488488 if internal .LogLevel .WarnOrAbove () {
489- internal . Logger . Printf (ctx , logs .NoPoolProvidedCannotRemove (conn .GetID (), err ))
489+ hwm . logf (ctx , logs .NoPoolProvidedCannotRemove (conn .GetID (), err ))
490490 }
491491 }
492492}
493+
494+ func (hwm * handoffWorkerManager ) logf (ctx context.Context , format string , args ... interface {}) {
495+ if hwm .config != nil && hwm .config .Logger != nil {
496+ hwm .config .Logger .Printf (ctx , format , args ... )
497+ } else {
498+ internal .Logger .Printf (ctx , format , args ... )
499+ }
500+ }
0 commit comments