Add LogLines class

This commit is contained in:
René Stadler 2007-11-21 10:47:40 +02:00 committed by Stefan Sauer
parent f98ece8fe6
commit 03713f4a0e

View file

@ -300,6 +300,35 @@ class LogLine (list):
category, filename, line, function,
object_, message,)
class LogLines (object):
def __init__ (self, fileobj, line_cache):
self.__fileobj = fileobj
self.__line_cache = line_cache
def __len__ (self):
return len (self.__line_cache.offsets)
def __getitem__ (self, line_index):
offset = self.__line_cache.offsets[line_index]
self.__fileobj.seek (offset)
line_string = self.__fileobj.readline ()
line = LogLine.parse_full (line_string)
msg = line_string[line[-1]:]
line[-1] = msg
return line
def __iter__ (self):
l = len (self)
i = 0
while i < l:
yield self[i]
i += 1
class LogFile (Producer):
def __init__ (self, filename, dispatcher):
@ -338,6 +367,8 @@ class LogFile (Producer):
def handle_load_finished (self):
self.lines = LogLines (self.fileobj, self.line_cache)
# Chain up to our consumers:
self.have_load_finished ()