@@ -3,6 +3,7 @@ package redis_test
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "log"
6
7
"net"
7
8
"os"
8
9
"strconv"
@@ -14,7 +15,6 @@ import (
14
15
. "github.com/bsm/ginkgo/v2"
15
16
. "github.com/bsm/gomega"
16
17
"github.com/redis/go-redis/v9"
17
- "github.com/redis/go-redis/v9/internal"
18
18
)
19
19
20
20
const (
55
55
sentinel1 , sentinel2 , sentinel3 * redis.Client
56
56
)
57
57
58
+ var TLogger * TestLogger
59
+
58
60
var cluster = & clusterScenario {
59
61
ports : []string {"16600" , "16601" , "16602" , "16603" , "16604" , "16605" },
60
62
nodeIDs : make ([]string , 6 ),
@@ -106,9 +108,10 @@ var _ = BeforeSuite(func() {
106
108
fmt .Printf ("CLIENT_LIBS_TEST_IMAGE: %v\n " , os .Getenv ("CLIENT_LIBS_TEST_IMAGE" ))
107
109
108
110
// set logger that will filter some of the noise from the tests
109
- tlogger := NewTestLogger ()
110
- tlogger .Filter ("ERR unknown subcommand 'maint_notifications'" )
111
- redis .SetLogger (tlogger )
111
+ TLogger := NewTestLogger ()
112
+ TLogger .Filter ("ERR unknown subcommand 'maint_notifications'" )
113
+ TLogger .Filter ("test panic" )
114
+ redis .SetLogger (TLogger )
112
115
113
116
if RedisVersion < 7.0 || RedisVersion > 9 {
114
117
panic ("incorrect or not supported redis version" )
@@ -408,8 +411,7 @@ func (h *hook) ProcessPipelineHook(hook redis.ProcessPipelineHook) redis.Process
408
411
}
409
412
410
413
func NewTestLogger () * TestLogger {
411
- intLogger := internal .Logger
412
-
414
+ intLogger := log .New (os .Stderr , "redis: " , log .LstdFlags | log .Lshortfile )
413
415
return & TestLogger {
414
416
intLogger ,
415
417
[]string {},
@@ -419,18 +421,31 @@ func NewTestLogger() *TestLogger {
419
421
// TestLogger is a logger that filters out specific substrings so
420
422
// the test output is not polluted with noise.
421
423
type TestLogger struct {
422
- intLogger internal.Logging
423
- filteredSugstrings []string
424
+ log * log.Logger
425
+ filteredSubstrings []string
426
+ }
427
+
428
+ // Filter adds a substring to the filter list.
429
+ func (tl * TestLogger ) Filter (substr string ) {
430
+ tl .filteredSubstrings = append (tl .filteredSubstrings , substr )
424
431
}
425
432
426
- func (t * TestLogger ) Filter (substr string ) {
427
- t .filteredSugstrings = append (t .filteredSugstrings , substr )
433
+ // Unfilter removes a substring from the filter list.
434
+ func (tl * TestLogger ) Unfilter (substr string ) {
435
+ for i , s := range tl .filteredSubstrings {
436
+ if s == substr {
437
+ tl .filteredSubstrings = append (tl .filteredSubstrings [:i ], tl .filteredSubstrings [i + 1 :]... )
438
+ return
439
+ }
440
+ }
428
441
}
429
- func (t * TestLogger ) Printf (_ context.Context , format string , v ... interface {}) {
430
- for _ , substr := range t .filteredSugstrings {
431
- if strings .Contains (format , substr ) {
442
+
443
+ func (tl * TestLogger ) Printf (_ context.Context , format string , v ... interface {}) {
444
+ msg := fmt .Sprintf (format , v ... )
445
+ for _ , substr := range tl .filteredSubstrings {
446
+ if strings .Contains (msg , substr ) {
432
447
return
433
448
}
434
449
}
435
- t . intLogger . Printf ( ctx , format , v ... )
450
+ _ = tl . log . Output ( 2 , msg )
436
451
}
0 commit comments