@@ -45,7 +45,6 @@ import (
4545// when searching for logs
4646type Logger struct {
4747 * logp.Logger
48- t * testing.T
4948 logFile * os.File
5049 offset int64
5150}
@@ -68,7 +67,6 @@ func NewFileLogger(t *testing.T) *Logger {
6867 core := zapcore .NewCore (encoder , zapcore .AddSync (f ), zap .DebugLevel )
6968
7069 tl := & Logger {
71- t : t ,
7270 logFile : f ,
7371 }
7472
@@ -115,12 +113,12 @@ func NewFileLogger(t *testing.T) *Logger {
115113// subsequent call to WaitLogsContains will only check logs not yet evaluated.
116114// msgAndArgs should be a format string and arguments that will be printed
117115// if the logs are not found, providing additional context for debugging.
118- func (l * Logger ) WaitLogsContains (s string , timeout time.Duration , msgAndArgs ... any ) {
119- l . t .Helper ()
116+ func (l * Logger ) WaitLogsContains (t * testing. T , s string , timeout time.Duration , msgAndArgs ... any ) {
117+ t .Helper ()
120118 require .EventuallyWithT (
121- l . t ,
119+ t ,
122120 func (c * assert.CollectT ) {
123- found , err := l .logContains (s )
121+ found , err := l .LogContains (s )
124122 if err != nil {
125123 c .Errorf ("cannot check the log file: %s" , err )
126124 return
@@ -135,25 +133,25 @@ func (l *Logger) WaitLogsContains(s string, timeout time.Duration, msgAndArgs ..
135133 msgAndArgs ... )
136134}
137135
138- // logContains searches for str in the log file keeping track of the offset.
139- // If there is any issue reading the log file, then t.Fatalf is called,
140- // if str is not present in the logs, t.Fatalf is called.
141- func (l * Logger ) LogContains ( str string ) {
142- l . t .Helper ()
143- found , err := l .logContains (str )
136+ // RequireLogContains searches for str in the log file keeping track of the
137+ // offset. If there is any issue reading the log file, then t.Fatalf is called,
138+ // if str is not present in the logs, t.Errorf is called.
139+ func (l * Logger ) RequireLogContains ( t * testing. T , str string ) {
140+ t .Helper ()
141+ found , err := l .LogContains (str )
144142 if err != nil {
145- l . t .Fatalf ("cannot read log file: %s" , err )
143+ t .Fatalf ("cannot read log file: %s" , err )
146144 }
147145
148146 if ! found {
149- l . t . Fatalf ("'%s' not found in logs" , str )
147+ t . Errorf ("'%s' not found in logs" , str )
150148 }
151149}
152150
153151// logContains searches for str in the log file keeping track of the offset.
154152// It returns true if str is found in the logs. If there are any errors,
155153// it returns false and the error
156- func (l * Logger ) logContains (str string ) (bool , error ) {
154+ func (l * Logger ) LogContains (str string ) (bool , error ) {
157155 // Open the file again so we can seek and not interfere with
158156 // the logger writing to it.
159157 f , err := os .Open (l .logFile .Name ())
0 commit comments