summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2018-10-18 20:58:12 +0200
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2018-10-18 22:01:26 +0200
commitd967c246c8168d923fd3c3e5ada28d49f9d3ee8e (patch)
tree8153037d95c9afdb0f3e5a842959a912e69fcb87
parenta630f4a13ddecb2c7c8e9f9db08ef87646f6bb29 (diff)
downloadpoezio-d967c246c8168d923fd3c3e5ada28d49f9d3ee8e.tar.gz
poezio-d967c246c8168d923fd3c3e5ada28d49f9d3ee8e.tar.bz2
poezio-d967c246c8168d923fd3c3e5ada28d49f9d3ee8e.tar.xz
poezio-d967c246c8168d923fd3c3e5ada28d49f9d3ee8e.zip
logger: Look up the correct start position, not two bytes before.
-rw-r--r--poezio/logger.py13
1 files changed, 5 insertions, 8 deletions
diff --git a/poezio/logger.py b/poezio/logger.py
index f5973fa7..fa83c966 100644
--- a/poezio/logger.py
+++ b/poezio/logger.py
@@ -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
"""
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,
- # after a \n
+ # start of messages begin with MI or MR, after a \n
+ pos = m.rfind(b"\nM") + 1
# number of message found so far
count = 0
- while pos != -1 and count < nb - 1:
+ while pos != 0 and count < nb - 1:
count += 1
- pos = m.rfind(b"\nM", 0, pos)
- if pos == -1: # If we don't have enough lines in the file
- 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()
+ pos = m.rfind(b"\nM", 0, pos) + 1
+ lines = m[pos:].decode(errors='replace').splitlines()
return lines