File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed
Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -274,13 +274,38 @@ def add_ignore_rule(
274274 infile .write (f"{ files_glob } ;;{ skip_after } ;;{ regex } \n " )
275275
276276
277+ def find_msgs_in_logs (
278+ regex : str ,
279+ logfile : pl .Path ,
280+ seek_offset : int ,
281+ timestamp : float ,
282+ only_first : bool = False ,
283+ ) -> tp .List [str ]:
284+ """Find messages in log."""
285+ regex_comp = re .compile (regex )
286+ lines_found = []
287+ for logfile_rec in _get_rotated_logs (
288+ logfile = pl .Path (logfile ), seek = seek_offset , timestamp = timestamp
289+ ):
290+ with open (logfile_rec .logfile , encoding = "utf-8" ) as infile :
291+ infile .seek (logfile_rec .seek )
292+ for line in infile :
293+ if regex_comp .search (line ):
294+ lines_found .append (line )
295+ if only_first :
296+ break
297+ if lines_found and only_first :
298+ break
299+ return lines_found
300+
301+
277302def check_msgs_presence_in_logs (
278303 regex_pairs : tp .List [tp .Tuple [str , str ]],
279304 seek_offsets : tp .Dict [str , int ],
280305 state_dir : pl .Path ,
281306 timestamp : float ,
282307) -> tp .List [str ]:
283- """Make sure the expected messages are present in logs."""
308+ """Check if the expected messages are present in logs."""
284309 errors = []
285310 for files_glob , regex in regex_pairs :
286311 regex_comp = re .compile (regex )
You can’t perform that action at this time.
0 commit comments