Changeset 26:7268d9742986 in livinglogic.python.tipimaid

Show
Ignore:
Timestamp:
11/27/08 16:55:48 (10 years ago)
Author:
Nikolas Tautenhahn <nik@…>
Branch:
default
Message:

buffertime = 0 disables buffering

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • liaalh.py

    r25 r26  
    2222        self.servers = {} 
    2323        self.buffertime = datetime.timedelta(seconds=buffertime) 
     24        self.buffer_enabled = buffertime > 0 
    2425        self.stream = stream 
    2526        self.re_find_date = re.compile(" \[(.*?)\] ") 
     
    2930 
    3031    def add(self, logline): 
    31         if not self.data or self.data[-1] <= logline: 
     32        if not self.buffer_enabled or self.data or self.data[-1] <= logline: 
    3233            self.data.append(logline) 
    3334        else: 
     
    4142        while self.data: 
    4243            line = self.data[0] 
    43             if not all: 
     44            if not all and self.buffer_enabled: 
    4445                utcnow = datetime.datetime.utcnow() 
    4546                if utcnow - line[0] < self.buffertime: 
     
    7879        temp = d.split() 
    7980        utcdate = datetime.datetime(*(time.strptime(temp[0], "%d/%b/%Y:%H:%M:%S")[0:6])) # support ancient distributions with python < 2.5 
    80 #       utcdate = datetime.datetime.strptime(temp[0], "%d/%b/%Y:%H:%M:%S") 
    8181        minsoff = int("%s%s" % (temp[1][0], temp[1][-2:])) 
    8282        hrsoff = int("%s%s" % (temp[1][0], temp[1][1:3])) 
     
    9696                if not line: 
    9797                    break 
    98                 datestring = self.re_find_date.findall(line)[0] 
    99                 utctime = self.apachedate2utc(datestring) 
     98                if self.buffer_enabled: 
     99                    datestring = self.re_find_date.findall(line)[0] 
     100                    utctime = self.apachedate2utc(datestring) 
     101                else: 
     102                    utctime = None 
    100103                if self.handlevirtualhost: 
    101104                    (server, data) = line.split(None, 1) 
     
    117120    p = optparse.OptionParser(usage="usage: %prog filename-pattern [options]") 
    118121    p.add_option("-z", "--gzip", dest="gzip", type="int", action="store", help="If set, logs are gzipped with this compression level (lowest: 1, highest: 9)", default=None) 
    119     p.add_option("-b", "--buffertime", dest="buffertime", type="int", action="store", help="Time in seconds for which log entries are buffered, default=10", default=10) 
     122    p.add_option("-b", "--buffertime", dest="buffertime", type="int", action="store", help="Time in seconds for which log entries are buffered, default=10. Set to 0 to disable buffering", default=10) 
    120123    (options, args) = p.parse_args() 
    121124    if options.gzip is not None: