@@ -54,9 +54,13 @@ def get(self):
54
54
include = include .casefold ()
55
55
exclude = exclude .casefold ()
56
56
57
+ # regular expression to identify the start of a log record (timestamp-based)
58
+ record_start_pattern = re .compile (r"^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}" )
59
+
57
60
with io .open (get_log_file_path (), encoding = 'UTF-8' ) as file :
58
61
raw_lines = file .read ()
59
62
lines = raw_lines .split ('|\n ' )
63
+ multi_line_record = []
60
64
for line in lines :
61
65
if line == '' :
62
66
continue
@@ -86,18 +90,34 @@ def get(self):
86
90
skip = exclude in compare_line
87
91
if skip :
88
92
continue
89
- raw_message = line .split ('|' )
90
- raw_message_len = len (raw_message )
91
- if raw_message_len > 3 :
92
- log = dict ()
93
- log ["timestamp" ] = raw_message [0 ]
94
- log ["type" ] = raw_message [1 ].rstrip ()
95
- log ["message" ] = raw_message [3 ]
96
- if raw_message_len > 4 and raw_message [4 ] != '\n ' :
97
- log ['exception' ] = raw_message [4 ].strip ('\' ' ).replace (' ' , '\u2003 \u2003 ' )
98
- else :
99
- log ['exception' ] = None
100
- logs .append (log )
93
+ # check if the line has a timestamp that matches the start of a new log record
94
+ if record_start_pattern .match (line ):
95
+ if multi_line_record :
96
+ # finalize the multi line record and update the exception of the last entry
97
+ last_log = logs [- 1 ]
98
+ last_log ["exception" ] += "\n " + "\n " .join (multi_line_record )
99
+ # reset for the next multi-line record
100
+ multi_line_record = []
101
+ raw_message = line .split ('|' )
102
+ raw_message_len = len (raw_message )
103
+ if raw_message_len > 3 :
104
+ log = dict ()
105
+ log ["timestamp" ] = raw_message [0 ]
106
+ log ["type" ] = raw_message [1 ].rstrip ()
107
+ log ["message" ] = raw_message [3 ]
108
+ if raw_message_len > 4 and raw_message [4 ] != '\n ' :
109
+ log ['exception' ] = raw_message [4 ].strip ('\' ' ).replace (' ' , '\u2003 \u2003 ' )
110
+ else :
111
+ log ['exception' ] = None
112
+ logs .append (log )
113
+ else :
114
+ # accumulate lines that do not have new record header timestamps
115
+ multi_line_record .append (line .strip ())
116
+
117
+ if multi_line_record :
118
+ # finalize the multi line record and update the exception of the last entry
119
+ last_log = logs [- 1 ]
120
+ last_log ["exception" ] += "\n " .join (multi_line_record )
101
121
102
122
logs .reverse ()
103
123
return marshal (logs , self .get_response_model , envelope = 'data' )
0 commit comments