Really make the use_log a tab-specific option.
and do not read the whole log file for the last lines.
This commit is contained in:
parent
08ca9bd5c5
commit
423bae05b0
1 changed files with 15 additions and 6 deletions
|
@ -49,7 +49,7 @@ class Logger(object):
|
||||||
Check that the directory where we want to log the messages
|
Check that the directory where we want to log the messages
|
||||||
exists. if not, create it
|
exists. if not, create it
|
||||||
"""
|
"""
|
||||||
if config.get_by_tabname('use_log', 'false', room) == 'false':
|
if config.get('use_log', 'false') == 'false':
|
||||||
return None
|
return None
|
||||||
directory = os.path.join(DATA_HOME, 'logs')
|
directory = os.path.join(DATA_HOME, 'logs')
|
||||||
try:
|
try:
|
||||||
|
@ -67,17 +67,26 @@ class Logger(object):
|
||||||
"""
|
"""
|
||||||
Get the log history for the given jid
|
Get the log history for the given jid
|
||||||
"""
|
"""
|
||||||
|
if config.get_by_tabname('use_log', 'false', jid) == 'false':
|
||||||
|
return
|
||||||
|
|
||||||
if nb <= 0:
|
if nb <= 0:
|
||||||
return None
|
return
|
||||||
directory = os.path.join(DATA_HOME, 'logs')
|
directory = os.path.join(DATA_HOME, 'logs')
|
||||||
try:
|
try:
|
||||||
fd = open(os.path.join(directory, jid), 'r')
|
fd = open(os.path.join(directory, jid), 'r')
|
||||||
except:
|
except:
|
||||||
return None
|
return
|
||||||
else:
|
if not fd:
|
||||||
if not fd:
|
return
|
||||||
return None
|
|
||||||
|
|
||||||
|
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()
|
logs = fd.readlines()
|
||||||
fd.close()
|
fd.close()
|
||||||
return logs[-nb:]
|
return logs[-nb:]
|
||||||
|
|
Loading…
Reference in a new issue