Commit 68c9139f authored by Aurel's avatar Aurel

add methods to tail the event log file


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38162 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8324f591
...@@ -172,7 +172,7 @@ class IntrospectionTool(LogMixin, BaseTool): ...@@ -172,7 +172,7 @@ class IntrospectionTool(LogMixin, BaseTool):
file_path='log/Z2.log', file_path='log/Z2.log',
compressed=compressed) compressed=compressed)
security.declareProtected(Permissions.ManagePortal, 'getAccessLog') security.declareProtected(Permissions.ManagePortal, 'getEventLog')
def getEventLog(self, compressed=1, REQUEST=None): def getEventLog(self, compressed=1, REQUEST=None):
""" """
Get the Event Log. Get the Event Log.
...@@ -186,6 +186,52 @@ class IntrospectionTool(LogMixin, BaseTool): ...@@ -186,6 +186,52 @@ class IntrospectionTool(LogMixin, BaseTool):
file_path='log/event.log', file_path='log/event.log',
compressed=compressed) compressed=compressed)
def _tailFile(self, file_name, line_number=10):
"""
Do a 'tail -f -n line_number filename'
"""
log_file = os.path.join(getConfiguration().instancehome, file_name)
if not os.path.exists(log_file):
raise IOError, 'The file: %s does not exist.' % log_file
char_per_line=75
tailed_file = open(log_file,'r')
while 1:
try:
tailed_file.seek(-1 * char_per_line * line_number, 2)
except IOError:
tailed_file.seek(0)
if tailed_file.tell() == 0:
at_start = 1
else:
at_start = 0
lines = tailed_file.read().split("\n")
if (len(lines) > (line_number + 1)) or at_start:
break
# The lines are bigger than we thought
char_per_line = char_per_line * 1.3 # Inc for retry
tailed_file.close()
if len(lines) > line_number:
start = len(lines) - line_number - 1
else:
start = 0
return "\n".join(lines[start:len(lines)])
security.declareProtected(Permissions.ManagePortal, 'tailEventLog')
def tailEventLog(self):
"""
Tail the Event Log.
"""
return self._tailFile('log/event.log', 50)
security.declareProtected(Permissions.ManagePortal, 'getAccessLog') security.declareProtected(Permissions.ManagePortal, 'getAccessLog')
def getDataFs(self, compressed=1, REQUEST=None): def getDataFs(self, compressed=1, REQUEST=None):
""" """
......
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