Update examples/python-loganalysis/loganalysis.py

Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
This commit is contained in:
Matt Williams 2023-11-14 10:31:05 -08:00 committed by GitHub
parent eced0d52ab
commit 64b7e0c218
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,16 +16,12 @@ def find_errors_in_log_file():
with open(log_file_path, 'r') as log_file:
log_lines = log_file.readlines()
error_lines = []
for i, line in enumerate(log_lines):
if re.search('error', line, re.IGNORECASE):
error_lines.append(i)
error_logs = []
for error_line in error_lines:
start_index = max(0, error_line - prelines)
end_index = min(len(log_lines), error_line + postlines)
error_logs.extend(log_lines[start_index:end_index])
error_logs = []
for i, line in enumerate(log_lines):
if "error" in line.lower():
start_index = max(0, i - prelines)
end_index = min(len(log_lines), i + postlines + 1)
error_logs.extend(log_lines[start_index:end_index])
return error_logs