Commit d967c246 authored by Link Mauve's avatar Link Mauve

logger: Look up the correct start position, not two bytes before.

parent a630f4a1
Pipeline #1742 failed with stages
in 1 minute and 34 seconds
...@@ -295,17 +295,14 @@ def _get_lines_from_fd(fd: IO[Any], nb: int = 10) -> List[str]: ...@@ -295,17 +295,14 @@ def _get_lines_from_fd(fd: IO[Any], nb: int = 10) -> List[str]:
Get the last log lines from a fileno Get the last log lines from a fileno
""" """
with mmap.mmap(fd.fileno(), 0, prot=mmap.PROT_READ) as m: with mmap.mmap(fd.fileno(), 0, prot=mmap.PROT_READ) as m:
pos = m.rfind(b"\nM") # start of messages begin with MI or MR, # start of messages begin with MI or MR, after a \n
# after a \n pos = m.rfind(b"\nM") + 1
# number of message found so far # number of message found so far
count = 0 count = 0
while pos != -1 and count < nb - 1: while pos != 0 and count < nb - 1:
count += 1 count += 1
pos = m.rfind(b"\nM", 0, pos) pos = m.rfind(b"\nM", 0, pos) + 1
if pos == -1: # If we don't have enough lines in the file lines = m[pos:].decode(errors='replace').splitlines()
pos = 1 # 1, because we do -1 just on the next line
# to get 0 (start of the file)
lines = m[pos - 1:].decode(errors='replace').splitlines()
return lines return lines
......
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