From 603d521bbdd0a02a418e6d788892a9c6e48f5b8a Mon Sep 17 00:00:00 2001 From: "Jeroen van Meeuwen (Kolab Systems)" Date: Tue, 4 Dec 2012 15:15:26 +0000 Subject: Only use sys.argv if they are indeed specified Suppress the messages about not being able to chown our log file. What we are actually interested in is whether we can write to it. --- pykolab/logger.py | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/pykolab/logger.py b/pykolab/logger.py index 7bd0bd4..c812261 100644 --- a/pykolab/logger.py +++ b/pykolab/logger.py @@ -38,28 +38,29 @@ class Logger(logging.Logger): fork = False loglevel = logging.CRITICAL - for arg in sys.argv: - if debuglevel == -1: - debuglevel = int(arg) - loglevel = logging.DEBUG - break - - if '-d' == arg: - debuglevel = -1 - continue - - if '-l' == arg: - loglevel = -1 - continue - - if '--fork' == arg: - fork = True - - if loglevel == -1: - if hasattr(logging,arg.upper()): - loglevel = getattr(logging,arg.upper()) - else: + if hasattr(sys, 'argv'): + for arg in sys.argv: + if debuglevel == -1: + debuglevel = int(arg) loglevel = logging.DEBUG + break + + if '-d' == arg: + debuglevel = -1 + continue + + if '-l' == arg: + loglevel = -1 + continue + + if '--fork' == arg: + fork = True + + if loglevel == -1: + if hasattr(logging,arg.upper()): + loglevel = getattr(logging,arg.upper()) + else: + loglevel = logging.DEBUG def __init__(self, *args, **kw): if kw.has_key('name'): @@ -102,10 +103,7 @@ class Logger(logging.Logger): ) os.chmod(self.logfile, 0660) except: - print >> sys.stderr, \ - _("Could not change the ownership of log file %s") % ( - self.logfile - ) + pass # Make sure the log file exists try: @@ -144,5 +142,6 @@ class Logger(logging.Logger): if level <= self.debuglevel: # TODO: Not the way it's supposed to work! self.log(logging.DEBUG, '[%d]: %s' % (os.getpid(),msg)) + logging.setLoggerClass(Logger) -- cgit v1.1