mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-06-27 17:09:34 -04:00
Handle multiline log output without proper log file timestamp headers like produced by KnowIt errors
This commit is contained in:
parent
d6e7773a0f
commit
e91b71c6ec
1 changed files with 32 additions and 12 deletions
|
@ -54,9 +54,13 @@ class SystemLogs(Resource):
|
|||
include = include.casefold()
|
||||
exclude = exclude.casefold()
|
||||
|
||||
# regular expression to identify the start of a log record (timestamp-based)
|
||||
record_start_pattern = re.compile(r"^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}")
|
||||
|
||||
with io.open(get_log_file_path(), encoding='UTF-8') as file:
|
||||
raw_lines = file.read()
|
||||
lines = raw_lines.split('|\n')
|
||||
multi_line_record = []
|
||||
for line in lines:
|
||||
if line == '':
|
||||
continue
|
||||
|
@ -86,6 +90,14 @@ class SystemLogs(Resource):
|
|||
skip = exclude in compare_line
|
||||
if skip:
|
||||
continue
|
||||
# check if the line has a timestamp that matches the start of a new log record
|
||||
if record_start_pattern.match(line):
|
||||
if multi_line_record:
|
||||
# finalize the multi line record and update the exception of the last entry
|
||||
last_log = logs[-1]
|
||||
last_log["exception"] += "\n" + "\n".join(multi_line_record)
|
||||
# reset for the next multi-line record
|
||||
multi_line_record = []
|
||||
raw_message = line.split('|')
|
||||
raw_message_len = len(raw_message)
|
||||
if raw_message_len > 3:
|
||||
|
@ -98,6 +110,14 @@ class SystemLogs(Resource):
|
|||
else:
|
||||
log['exception'] = None
|
||||
logs.append(log)
|
||||
else:
|
||||
# accumulate lines that do not have new record header timestamps
|
||||
multi_line_record.append(line.strip())
|
||||
|
||||
if multi_line_record:
|
||||
# finalize the multi line record and update the exception of the last entry
|
||||
last_log = logs[-1]
|
||||
last_log["exception"] += "\n".join(multi_line_record)
|
||||
|
||||
logs.reverse()
|
||||
return marshal(logs, self.get_response_model, envelope='data')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue