mirror of
https://github.com/logos-blockchain/logos-blockchain-e2e-tests.git
synced 2026-05-22 01:09:32 +00:00
fix: simplify search_log_for_keywords
This commit is contained in:
parent
26c4aecd95
commit
948446e599
@ -152,20 +152,16 @@ class DockerManager:
|
|||||||
def search_log_for_keywords(self, log_path, keywords, use_regex=False, log_stream=None):
|
def search_log_for_keywords(self, log_path, keywords, use_regex=False, log_stream=None):
|
||||||
matches = {keyword: [] for keyword in keywords}
|
matches = {keyword: [] for keyword in keywords}
|
||||||
|
|
||||||
# Read from stream
|
if log_stream is None:
|
||||||
if log_stream is not None:
|
log_stream = open(log_path, "r")
|
||||||
for line in log_stream:
|
|
||||||
line_matches = self.find_keywords_in_line(keywords, line.decode("utf-8"), use_regex=use_regex)
|
|
||||||
for keyword, result in line_matches.items():
|
|
||||||
matches[keyword].extend(result)
|
|
||||||
|
|
||||||
else:
|
for line in log_stream:
|
||||||
# Open the log file and search line by line
|
# Decode line if it is a byte object not str
|
||||||
with open(log_path, "r") as log_file:
|
if hasattr(line, "decode"):
|
||||||
for line in log_file:
|
line = line.decode("utf-8")
|
||||||
line_matches = self.find_keywords_in_line(keywords, line, use_regex=use_regex)
|
line_matches = self.find_keywords_in_line(keywords, line, use_regex=use_regex)
|
||||||
for keyword, result in line_matches.items():
|
for keyword, result in line_matches.items():
|
||||||
matches[keyword].extend(result)
|
matches[keyword].extend(result)
|
||||||
|
|
||||||
# Check if there were any matches
|
# Check if there were any matches
|
||||||
if any(matches_list for matches_list in matches.values()):
|
if any(matches_list for matches_list in matches.values()):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user