Update examples/python-loganalysis/loganalysis.py
Co-authored-by: Bruce MacDonald <brucewmacdonald@gmail.com>
This commit is contained in:
parent
eced0d52ab
commit
64b7e0c218
1 changed files with 6 additions and 10 deletions
|
@ -16,15 +16,11 @@ def find_errors_in_log_file():
|
||||||
with open(log_file_path, 'r') as log_file:
|
with open(log_file_path, 'r') as log_file:
|
||||||
log_lines = log_file.readlines()
|
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 = []
|
error_logs = []
|
||||||
for error_line in error_lines:
|
for i, line in enumerate(log_lines):
|
||||||
start_index = max(0, error_line - prelines)
|
if "error" in line.lower():
|
||||||
end_index = min(len(log_lines), error_line + postlines)
|
start_index = max(0, i - prelines)
|
||||||
|
end_index = min(len(log_lines), i + postlines + 1)
|
||||||
error_logs.extend(log_lines[start_index:end_index])
|
error_logs.extend(log_lines[start_index:end_index])
|
||||||
|
|
||||||
return error_logs
|
return error_logs
|
||||||
|
|
Loading…
Reference in a new issue