summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2012-12-15 23:23:12 +0100
committermathieui <mathieui@mathieui.net>2012-12-15 23:23:12 +0100
commit423bae05b0ce47607569acdb0d36cd048f96c8f8 (patch)
treed3407792aa45420cc15effd354acb2e93563137c
parent08ca9bd5c59dd09368958724467c1dbabb0205df (diff)
downloadpoezio-423bae05b0ce47607569acdb0d36cd048f96c8f8.tar.gz
poezio-423bae05b0ce47607569acdb0d36cd048f96c8f8.tar.bz2
poezio-423bae05b0ce47607569acdb0d36cd048f96c8f8.tar.xz
poezio-423bae05b0ce47607569acdb0d36cd048f96c8f8.zip
Really make the use_log a tab-specific option.
and do not read the whole log file for the last lines.
-rw-r--r--src/logger.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/logger.py b/src/logger.py
index c4140347..da1aa09b 100644
--- a/src/logger.py
+++ b/src/logger.py
@@ -49,7 +49,7 @@ class Logger(object):
Check that the directory where we want to log the messages
exists. if not, create it
"""
- if config.get_by_tabname('use_log', 'false', room) == 'false':
+ if config.get('use_log', 'false') == 'false':
return None
directory = os.path.join(DATA_HOME, 'logs')
try:
@@ -67,17 +67,26 @@ class Logger(object):
"""
Get the log history for the given jid
"""
+ if config.get_by_tabname('use_log', 'false', jid) == 'false':
+ return
+
if nb <= 0:
- return None
+ return
directory = os.path.join(DATA_HOME, 'logs')
try:
fd = open(os.path.join(directory, jid), 'r')
except:
- return None
- else:
- if not fd:
- return None
+ return
+ if not fd:
+ return
+ pos = fd.seek(0, 2)
+ while len(fd.readlines()) < nb + 1:
+ pos -= 100
+ if pos < 0:
+ break
+ fd.seek(pos)
+ fd.seek(pos)
logs = fd.readlines()
fd.close()
return logs[-nb:]