diff --git a/internal/log.go b/internal/log.go index 4fe3d7db..dd0e3d0c 100644 --- a/internal/log.go +++ b/internal/log.go @@ -27,13 +27,3 @@ func (l *logger) Printf(ctx context.Context, format string, v ...interface{}) { var Logger Logging = &logger{ log: log.New(os.Stderr, "redis: ", log.LstdFlags|log.Lshortfile), } - -// VoidLogger is a logger that does nothing. -// Used to disable logging and thus speed up the library. -type VoidLogger struct{} - -func (v *VoidLogger) Printf(_ context.Context, _ string, _ ...interface{}) { - // do nothing -} - -var _ Logging = (*VoidLogger)(nil) diff --git a/internal/pool/pool.go b/internal/pool/pool.go index 32e92218..70052220 100644 --- a/internal/pool/pool.go +++ b/internal/pool/pool.go @@ -385,7 +385,7 @@ func (p *ConnPool) getConn(ctx context.Context) (*Conn, error) { attempts := 0 for { if attempts >= getAttempts { - internal.Logger.Printf(ctx, "redis: connection pool: failed to get a connection accepted by hook after %d attempts", attempts) + internal.Logger.Printf(ctx, "redis: connection pool: was not able to get a connection accepted by hook after %d attempts", attempts) break } attempts++ diff --git a/main_test.go b/main_test.go index 29e6014b..dc778603 100644 --- a/main_test.go +++ b/main_test.go @@ -103,6 +103,9 @@ var _ = BeforeSuite(func() { fmt.Printf("REDIS_VERSION: %.1f\n", RedisVersion) fmt.Printf("CLIENT_LIBS_TEST_IMAGE: %v\n", os.Getenv("CLIENT_LIBS_TEST_IMAGE")) + tlogger := &TestLogger{} + tlogger.Filter("ERR unknown subcommand 'maint_notifications'") + redis.SetLogger(tlogger) if RedisVersion < 7.0 || RedisVersion > 9 { panic("incorrect or not supported redis version") } @@ -399,3 +402,21 @@ func (h *hook) ProcessPipelineHook(hook redis.ProcessPipelineHook) redis.Process } return hook } + +// TestLogger is a logger that filters out specific substrings so +// the test output is not polluted with noise. +type TestLogger struct { + filteredSugstrings []string +} + +func (t *TestLogger) Filter(substr string) { + t.filteredSugstrings = append(t.filteredSugstrings, substr) +} +func (t *TestLogger) Printf(ctx context.Context, format string, v ...interface{}) { + for _, substr := range t.filteredSugstrings { + if strings.Contains(format, substr) { + return + } + } + fmt.Printf(format, v...) +} diff --git a/redis.go b/redis.go index c2791336..13c7feca 100644 --- a/redis.go +++ b/redis.go @@ -456,7 +456,7 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error { c.optLock.Unlock() return fmt.Errorf("failed to enable maintenance notifications: %w", hitlessHandshakeErr) default: // will handle auto and any other - internal.Logger.Printf(ctx, "hitless: auto mode fallback: hitless upgrades disabled due to handshake failure: %v", hitlessHandshakeErr) + internal.Logger.Printf(ctx, "hitless: auto mode fallback: hitless upgrades disabled due to handshake error: %v", hitlessHandshakeErr) c.opt.HitlessUpgradeConfig.Mode = hitless.MaintNotificationsDisabled c.optLock.Unlock() // auto mode, disable hitless upgrades and continue @@ -1280,3 +1280,13 @@ func (c *baseClient) pushNotificationHandlerContext(cn *pool.Conn) push.Notifica Conn: &connectionAdapter{conn: cn}, // Wrap in adapter for easier interface access } } + +// VoidLogger is a logger that does nothing. +// Used to disable logging and thus speed up the library. +type VoidLogger struct{} + +func (v *VoidLogger) Printf(_ context.Context, _ string, _ ...interface{}) { + // do nothing +} + +var _ internal.Logging = (*VoidLogger)(nil)