@@ -3,6 +3,7 @@ package redis_test
33import (
44 "context"
55 "fmt"
6+ "log"
67 "net"
78 "os"
89 "strconv"
5556 sentinel1 , sentinel2 , sentinel3 * redis.Client
5657)
5758
59+ var TLogger * TestLogger
60+
5861var cluster = & clusterScenario {
5962 ports : []string {"16600" , "16601" , "16602" , "16603" , "16604" , "16605" },
6063 nodeIDs : make ([]string , 6 ),
@@ -106,9 +109,10 @@ var _ = BeforeSuite(func() {
106109 fmt .Printf ("CLIENT_LIBS_TEST_IMAGE: %v\n " , os .Getenv ("CLIENT_LIBS_TEST_IMAGE" ))
107110
108111 // 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 )
112+ TLogger := NewTestLogger ()
113+ TLogger .Filter ("ERR unknown subcommand 'maint_notifications'" )
114+ TLogger .Filter ("test panic" )
115+ redis .SetLogger (TLogger )
112116
113117 if RedisVersion < 7.0 || RedisVersion > 9 {
114118 panic ("incorrect or not supported redis version" )
@@ -408,8 +412,7 @@ func (h *hook) ProcessPipelineHook(hook redis.ProcessPipelineHook) redis.Process
408412}
409413
410414func NewTestLogger () * TestLogger {
411- intLogger := internal .Logger
412-
415+ intLogger := log .New (os .Stderr , "redis: " , log .LstdFlags | log .Lshortfile ),
413416 return & TestLogger {
414417 intLogger ,
415418 []string {},
@@ -419,18 +422,31 @@ func NewTestLogger() *TestLogger {
419422// TestLogger is a logger that filters out specific substrings so
420423// the test output is not polluted with noise.
421424type TestLogger struct {
422- intLogger internal. Logging
423- filteredSugstrings []string
425+ log * log. Logger
426+ filteredSubstrings []string
424427}
425428
426- func (t * TestLogger ) Filter (substr string ) {
427- t .filteredSugstrings = append (t .filteredSugstrings , substr )
429+ // Filter adds a substring to the filter list.
430+ func (tl * TestLogger ) Filter (substr string ) {
431+ tl .filteredSubstrings = append (tl .filteredSubstrings , substr )
428432}
429- func (t * TestLogger ) Printf (_ context.Context , format string , v ... interface {}) {
430- for _ , substr := range t .filteredSugstrings {
431- if strings .Contains (format , substr ) {
433+
434+ // Unfilter removes a substring from the filter list.
435+ func (tl * TestLogger ) Unfilter (substr string ) {
436+ for i , s := range tl .filteredSubstrings {
437+ if s == substr {
438+ tl .filteredSubstrings = append (tl .filteredSubstrings [:i ], tl .filteredSubstrings [i + 1 :]... )
432439 return
433440 }
434441 }
435- t .intLogger .Printf (ctx , format , v ... )
436442}
443+
444+ func (tl * TestLogger ) Printf (_ context.Context , format string , v ... interface {}) {
445+ msg := fmt .Sprintf (format , v ... )
446+ for _ , substr := range tl .filteredSubstrings {
447+ if strings .Contains (msg , substr ) {
448+ return
449+ }
450+ }
451+ _ = tl .log .Output (2 , msg )
452+ }
0 commit comments