11package redis_test
22
33import (
4- "context"
54 "fmt"
6- "log"
75 "net"
86 "os"
97 "strconv"
@@ -15,6 +13,7 @@ import (
1513 . "github.com/bsm/ginkgo/v2"
1614 . "github.com/bsm/gomega"
1715 "github.com/redis/go-redis/v9"
16+ "github.com/redis/go-redis/v9/internal"
1817)
1918
2019const (
5554 sentinel1 , sentinel2 , sentinel3 * redis.Client
5655)
5756
58- var TLogger * TestLogger
59-
6057var cluster = & clusterScenario {
6158 ports : []string {"16600" , "16601" , "16602" , "16603" , "16604" , "16605" },
6259 nodeIDs : make ([]string , 6 ),
@@ -107,11 +104,11 @@ var _ = BeforeSuite(func() {
107104 fmt .Printf ("REDIS_VERSION: %.1f\n " , RedisVersion )
108105 fmt .Printf ("CLIENT_LIBS_TEST_IMAGE: %v\n " , os .Getenv ("CLIENT_LIBS_TEST_IMAGE" ))
109106
110- // set logger that will filter some of the noise from the tests
111- TLogger := NewTestLogger ()
112- TLogger . Filter ( "ERR unknown subcommand 'maint_notifications'" )
113- TLogger . Filter ( "test panic" )
114- redis .SetLogger (TLogger )
107+ filterLogger := internal . NewFilterLogger ([] string {
108+ "ERR unknown subcommand 'maint_notifications'" ,
109+ "test panic" ,
110+ } )
111+ redis .SetLogger (filterLogger )
115112
116113 if RedisVersion < 7.0 || RedisVersion > 9 {
117114 panic ("incorrect or not supported redis version" )
@@ -409,43 +406,3 @@ func (h *hook) ProcessPipelineHook(hook redis.ProcessPipelineHook) redis.Process
409406 }
410407 return hook
411408}
412-
413- func NewTestLogger () * TestLogger {
414- intLogger := log .New (os .Stderr , "redis: " , log .LstdFlags | log .Lshortfile )
415- return & TestLogger {
416- intLogger ,
417- []string {},
418- }
419- }
420-
421- // TestLogger is a logger that filters out specific substrings so
422- // the test output is not polluted with noise.
423- type TestLogger struct {
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 )
431- }
432-
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- }
441- }
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 ) {
447- return
448- }
449- }
450- _ = tl .log .Output (2 , msg )
451- }
0 commit comments