Skip to content

Commit

Permalink
fix raw log stitching
Browse files Browse the repository at this point in the history
  • Loading branch information
saikonen committed Jun 6, 2024
1 parent 98fa93a commit c1dff94
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,22 @@ def paginated_result(content_iterator: Callable, page: int = 1, line_total: int
total_pages = max(-(line_total // -limit), 1) if limit else 1
_offset = limit * (total_pages - page) if reverse_order else limit * (page - 1)
loglines = []
# lines included in the page should be [start, end[
for lineno, item in enumerate(content_iterator()):
ts, line = item
if limit and lineno > (_offset + limit):
break
if _offset and lineno < _offset:
if _offset and lineno <= _offset:
continue
l = line if output_raw else {"row": lineno, "timestamp": ts, "line": line}
if reverse_order:
loglines.insert(0, l)
else:
loglines.append(l)

if page != total_pages and loglines and output_raw:
# we want a trailing newline so raw logs get pieced together correctly
loglines.append("")

return {
"content": "\n".join(loglines) if output_raw else loglines,
Expand Down

0 comments on commit c1dff94

Please sign in to comment.