Unverified Commit 64b7e0c2 authored by Matt Williams's avatar Matt Williams Committed by GitHub
Browse files

Update examples/python-loganalysis/loganalysis.py


Co-authored-by: default avatarBruce MacDonald <brucewmacdonald@gmail.com>
parent eced0d52
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment