Skip to content

Commit 0fd9871

Browse files
committed
filter out logging
1 parent 4940827 commit 0fd9871

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

internal/log.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,3 @@ func (l *logger) Printf(ctx context.Context, format string, v ...interface{}) {
2727
var Logger Logging = &logger{
2828
log: log.New(os.Stderr, "redis: ", log.LstdFlags|log.Lshortfile),
2929
}
30-
31-
// VoidLogger is a logger that does nothing.
32-
// Used to disable logging and thus speed up the library.
33-
type VoidLogger struct{}
34-
35-
func (v *VoidLogger) Printf(_ context.Context, _ string, _ ...interface{}) {
36-
// do nothing
37-
}
38-
39-
var _ Logging = (*VoidLogger)(nil)

internal/pool/pool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ func (p *ConnPool) getConn(ctx context.Context) (*Conn, error) {
385385
attempts := 0
386386
for {
387387
if attempts >= getAttempts {
388-
internal.Logger.Printf(ctx, "redis: connection pool: failed to get a connection accepted by hook after %d attempts", attempts)
388+
internal.Logger.Printf(ctx, "redis: connection pool: was not able to get a connection accepted by hook after %d attempts", attempts)
389389
break
390390
}
391391
attempts++

main_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ var _ = BeforeSuite(func() {
103103
fmt.Printf("REDIS_VERSION: %.1f\n", RedisVersion)
104104
fmt.Printf("CLIENT_LIBS_TEST_IMAGE: %v\n", os.Getenv("CLIENT_LIBS_TEST_IMAGE"))
105105

106+
tlogger := &TestLogger{}
107+
tlogger.Filter("ERR unknown subcommand 'maint_notifications'")
108+
redis.SetLogger(tlogger)
106109
if RedisVersion < 7.0 || RedisVersion > 9 {
107110
panic("incorrect or not supported redis version")
108111
}
@@ -399,3 +402,21 @@ func (h *hook) ProcessPipelineHook(hook redis.ProcessPipelineHook) redis.Process
399402
}
400403
return hook
401404
}
405+
406+
// TestLogger is a logger that filters out specific substrings so
407+
// the test output is not polluted with noise.
408+
type TestLogger struct {
409+
filteredSugstrings []string
410+
}
411+
412+
func (t *TestLogger) Filter(substr string) {
413+
t.filteredSugstrings = append(t.filteredSugstrings, substr)
414+
}
415+
func (t *TestLogger) Printf(ctx context.Context, format string, v ...interface{}) {
416+
for _, substr := range t.filteredSugstrings {
417+
if strings.Contains(format, substr) {
418+
return
419+
}
420+
}
421+
fmt.Printf(format, v...)
422+
}

redis.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
456456
c.optLock.Unlock()
457457
return fmt.Errorf("failed to enable maintenance notifications: %w", hitlessHandshakeErr)
458458
default: // will handle auto and any other
459-
internal.Logger.Printf(ctx, "hitless: auto mode fallback: hitless upgrades disabled due to handshake failure: %v", hitlessHandshakeErr)
459+
internal.Logger.Printf(ctx, "hitless: auto mode fallback: hitless upgrades disabled due to handshake error: %v", hitlessHandshakeErr)
460460
c.opt.HitlessUpgradeConfig.Mode = hitless.MaintNotificationsDisabled
461461
c.optLock.Unlock()
462462
// auto mode, disable hitless upgrades and continue
@@ -1280,3 +1280,13 @@ func (c *baseClient) pushNotificationHandlerContext(cn *pool.Conn) push.Notifica
12801280
Conn: &connectionAdapter{conn: cn}, // Wrap in adapter for easier interface access
12811281
}
12821282
}
1283+
1284+
// VoidLogger is a logger that does nothing.
1285+
// Used to disable logging and thus speed up the library.
1286+
type VoidLogger struct{}
1287+
1288+
func (v *VoidLogger) Printf(_ context.Context, _ string, _ ...interface{}) {
1289+
// do nothing
1290+
}
1291+
1292+
var _ internal.Logging = (*VoidLogger)(nil)

0 commit comments

Comments
 (0)