Changeset 30:9fdd4ad3b38c in livinglogic.python.tipimaid

Show
Ignore:
Timestamp:
12/02/08 18:05:05 (10 years ago)
Author:
Nikolas Tautenhahn <nik@…>
Branch:
default
Message:

added utcrotate option to determine whether utc's \"now\" should be used for filenames and rotation

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • liaalh.py

    r29 r30  
    1616 
    1717class Buffer(object): 
    18     def __init__(self, pattern='', gzip_logs=None, buffertime=0, stream=sys.stdin): 
     18    def __init__(self, pattern='', gzip_logs=None, buffertime=0, stream=sys.stdin, utcrotate=False): 
    1919        self.pattern = pattern 
    2020        self.gzip_logs = gzip_logs 
     
    2626        if gzip_logs is not None and not pattern.endswith(".gz"): 
    2727            self.pattern = "%s.gz" % self.pattern 
     28        if utcrotate: 
     29            self.getnow = self.getutcnow() 
    2830        self.handlevirtualhost = "%v" in pattern 
    2931        self.run = self.run_buffered if buffertime > 0 else self.run_unbuffered 
     
    6062 
    6163    def writeline(self, server, line): 
    62         filename = datetime.datetime.now().strftime(self.pattern) 
     64        filename = self.getnow().strftime(self.pattern) 
    6365        if self.handlevirtualhost: 
    6466            filename = filename.replace("%v", server) 
     
    121123        return utcdate 
    122124 
     125    def getnow(self): 
     126        return datetime.datetime.now() 
     127 
     128    def getutcnow(self): 
     129        return datetime.datetime.utcnow() 
     130 
    123131    def sighandler(self, signum, frame): 
    124132        self.flushall() 
     
    132140    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) 
    133141    p.add_option("-b", "--buffertime", dest="buffertime", type="int", action="store", help="Time in seconds for which log entries are buffered, default=0. Set to 0 to disable buffering", default=0) 
     142    p.add_option("-u", "--utcrotate", dest="utcrotate", action="store_true", help="If set, UTC zime determines the time for filenames and rotation. Otherwise local time is used.", default=False) 
    134143    (options, args) = p.parse_args() 
    135144    if options.gzip is not None: 
     
    143152        sys.stderr.flush() 
    144153        return 1 
    145     buf = Buffer(pattern=args[0], gzip_logs=options.gzip, buffertime=options.buffertime) 
     154    buf = Buffer(pattern=args[0], gzip_logs=options.gzip, buffertime=options.buffertime, utcrotate=options.utcrotate) 
    146155    buf.run() 
    147156