1
0
mirror of https://github.com/redis/go-redis.git synced 2025-12-02 06:22:31 +03:00

feat: add optional logger wherever possible

This commit introduces an optional logger parameter to various structs.
This enhancement allows users to provide custom logging implementations.
This commit is contained in:
ccoVeille
2025-10-24 14:59:40 +02:00
parent 5b0b228a37
commit c98107019e
15 changed files with 340 additions and 172 deletions

View File

@@ -128,6 +128,9 @@ type Config struct {
// After this many retries, the connection will be removed from the pool.
// Default: 3
MaxHandoffRetries int
// Logger is an optional custom logger for maintenance notifications.
Logger internal.LoggerWithLevel
}
func (c *Config) IsEnabled() bool {
@@ -312,10 +315,9 @@ func (c *Config) ApplyDefaultsWithPoolConfig(poolSize int, maxActiveConns int) *
result.CircuitBreakerMaxRequests = c.CircuitBreakerMaxRequests
}
if internal.LogLevel.DebugOrAbove() {
internal.Logger.Printf(context.Background(), logs.DebugLoggingEnabled())
internal.Logger.Printf(context.Background(), logs.ConfigDebug(result))
}
c.logger().Debugf(context.Background(), logs.DebugLoggingEnabled())
c.logger().Debugf(context.Background(), logs.ConfigDebug(result))
return result
}
@@ -341,6 +343,8 @@ func (c *Config) Clone() *Config {
// Configuration fields
MaxHandoffRetries: c.MaxHandoffRetries,
Logger: c.Logger,
}
}
@@ -365,6 +369,13 @@ func (c *Config) applyWorkerDefaults(poolSize int) {
}
}
func (c *Config) logger() internal.LoggerWithLevel {
if c.Logger != nil {
return c.Logger
}
return internal.LegacyLoggerWithLevel
}
// DetectEndpointType automatically detects the appropriate endpoint type
// based on the connection address and TLS configuration.
//