Changeset 85:0a9b84c2964c in livinglogic.python.tipimaid

Show
Ignore:
Timestamp:
02/04/09 10:18:51 (10 years ago)
Author:
Nik Tautenhahn <nik@…>
Branch:
default
Message:

nicer error messages

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • liaalh.py

    r80 r85  
    11#!/usr/bin/env python 
    22# -*- coding: utf-8 -*- 
    3  
    4 # Apache sends a SIGTERM to its piped logger when it exits - when apache is killed with -9, it doesn't send anything 
    5 # TODO: Add an option to gzip a logfile when a new one is started 
    63 
    74import sys, os, datetime, errno, bisect, re, gzip, signal, time, threading 
     
    2320 
    2421class Buffer(object): 
    25     def __init__(self, pattern='', gzip_logs=None, buffertime=0, stream=sys.stdin, utcrotate=False, symlinkpattern=None, execute=None): 
     22    def __init__(self, pattern='', gzip_logs=None, buffertime=0, stream=sys.stdin, utcrotate=False, symlinkpattern=None, execute=None, progname="liaalh"): # TODO: Name 
    2623        self.pattern = pattern 
    2724        self.gzip_logs = gzip_logs 
     
    3835        self.handlevirtualhost = "%v" in pattern 
    3936        self.symlinkpattern = symlinkpattern 
     37        self.progname = progname 
    4038        if buffertime > 0: 
    4139            self.run = self.run_buffered 
     
    150148                retcode = os.system("%s %s" % (self.execute, filename)) 
    151149            if retcode != 0: 
    152                 sys.stderr.write("Subprocess \"%s %s\" returned error code %s" % (self.execute, filename, retcode)) 
     150                sys.stderr.write("[%s] [%s] Subprocess \"%s %s\" returned error code %s\n" % (datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), self.progname, self.execute, filename, retcode)) 
    153151                sys.stderr.flush() 
    154152        except OSError, exc: 
    155             sys.stderr.write("Subprocess \"%s %s\" caused exception %r" % (self.execute, filename, retcode)) 
     153            sys.stderr.write("[%s] [%s] Subprocess \"%s %s\" caused exception %r\n" % (datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), self.progname, self.execute, filename, retcode)) 
    156154            sys.stderr.flush() 
    157155 
     
    203201    p.add_option("-s", "--symlink", dest="symlinkpattern", metavar="FILEPATTERN", action="store", help="""Create a symlink pointing to the most recent log file (of each virtual host if you use %v). Needs a filename pattern for the symlink (e.g. %v/access.log or symlinks/access-%v.log). Only "%v" is allowed in the pattern as symlinks which include time/date data are useless.""", default=None) 
    204202    p.add_option("-x", "--execute", dest="execute", metavar="COMMAND", type="string", action="store", help="After writing to a logfile is finished and a new one is created (e.g. after rotating the logs), the given executable is started with the finished logfile as its first (and only) parameter. You could use gzip, bzip2, a self-written bash-script or even rm here.", default=None) 
    205     #TODO: What happens with execute's output? 
    206203    (options, args) = p.parse_args() 
    207204    if options.gzip is not None: 
     
    221218        return 1 
    222219 
    223     buf = Buffer(pattern=args[0], gzip_logs=options.gzip, buffertime=options.buffertime, utcrotate=options.utcrotate, symlinkpattern=options.symlinkpattern, execute=options.execute) 
     220    buf = Buffer(pattern=args[0], gzip_logs=options.gzip, buffertime=options.buffertime, utcrotate=options.utcrotate, symlinkpattern=options.symlinkpattern, execute=options.execute, progname=p.get_prog_name()) 
    224221    buf.run() 
    225222 
  • liaalh_sender.py

    r83 r85  
    133133                                    self.s = None 
    134134                                    self.buffer = self.buffer[i:] # the first i items were transmitted successfully 
    135                                     sys.stderr.write("%s (%s): Socket connection died again, while sending buffered data\n" % (self.progname, datetime.datetime.now().isoformat())) 
     135                                    sys.stderr.write("[%s] [liaalh_sender]: Socket connection died again, while sending buffered data\n" % (datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), self.progname)) 
    136136                                    return # our socket died while we were transmitting buffered items - go back to "normal" behaviour 
    137137                        else: # some buffered entries come too late, maybe because it took so long to wait for the server's response. 
     
    140140                            self.buffer = self.buffer[i:] # and the content which was transmitted to the server in time 
    141141                            return 
    142                     sys.stderr.write("%s (%s): Socket connection established again, all data could be sent to the server\n" % (self.progname, datetime.datetime.now().isoformat())) 
     142                    sys.stderr.write("[%s] [%s]: Socket connection established again, all data could be sent to the server\n" % (datetime.datetime.now().strftime("%a %b %d %H:%M:%S %Y"), self.progname)) 
    143143                    self.buffer = [] # if we arrive here everything was sent successfully 
    144144 
  • liaalh_server.py

    r84 r85  
    6666    import optparse 
    6767    p = optparse.OptionParser(usage="usage: %prog port") 
    68     p.add_option("-n", "--netcat-compatible", dest="netcat", action="store_true", help="If set, %prog switches to netcat-compatible mode. Otherwise %prog assumes that it talks to its own sender which has better recovery in case of a broken connection.\nDo NOT use this switch if you use liaalh_sender!", default=None) # TODO: Fix name 
     68    p.add_option("-n", "--netcat-compatible", dest="netcat", action="store_true", help="If set, %prog switches to netcat-compatible mode. Otherwise %prog assumes that it talks to its own sender which has better recovery in case of a broken connection.\nDo NOT use this switch if you use liaalh_sender!", default=None) # TODO: Fix name liaalh_sender 
    6969    (options, args) = p.parse_args() 
    7070    if len(args) != 1 or intify(args[0], None) is None: