log_parser.py
changeset 64 cdb6403c2498
parent 50 f13cf27a360b
child 65 8b50694f841e
--- a/log_parser.py	Mon Feb 09 07:32:11 2009 +0200
+++ b/log_parser.py	Mon Feb 09 11:05:53 2009 +0200
@@ -20,9 +20,11 @@
         self.tz = tz
         self.timestamp_fmt = timestamp_fmt
 
-    def parse_lines (self, lines, date=None) :
+    def parse_lines (self, lines, date=None, starting_offset=None) :
         """
             Parse the given (iterable) lines of unicode text into a LogEvent, no trailing newline.
+
+            Offset is the starting offset, and may be None to not use it.
             
             Giving date lets the parser build full timestamps, otherwise, unless line timestamps have full date
             information, event timestamps will have a date component of 1900/1/1.
@@ -36,12 +38,12 @@
         A parser for irssi logfiles
     """
 
-    def parse_lines (self, lines, date=None) :
+    def parse_lines (self, lines, date=None, starting_offset=None) :
         """
             Parse the given lines, yielding LogEvents. 
         """
         
-        for line in lines :
+        for offset, line in enumerate(lines) :
             # status lines
             if line.startswith('---') :
                 # XXX: handle these
@@ -62,6 +64,13 @@
                 # now localize with timezone
                 dtz = self.tz.localize(dt)
 
+                # offset?
+                if offset :
+                    offset = starting_offset + offset
+
+                else :
+                    offset = None
+
                 # yield raw events
-                yield log_line.LogLine(LogTypes.RAW, dtz, None, data)
+                yield log_line.LogLine(offset, LogTypes.RAW, dtz, None, data)