mirror of
https://github.com/redis/go-redis.git
synced 2025-09-02 22:01:16 +03:00
filter out logging
This commit is contained in:
@@ -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)
|
||||
|
@@ -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++
|
||||
|
21
main_test.go
21
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...)
|
||||
}
|
||||
|
12
redis.go
12
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)
|
||||
|
Reference in New Issue
Block a user