summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-04-10 11:20:26 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-04-10 11:20:26 +0100
commitbc0af8397060e65a265bc9ce22df17b1353bf436 (patch)
treed945f1fea6e71805fe60564f42bb1a750e891690
parent316771abdd0a9be7010936081d3b1fec900a5884 (diff)
downloadpykolab-bc0af8397060e65a265bc9ce22df17b1353bf436.tar.gz
Silence the stdout logger if it can detect we're meant to fork to the background
-rw-r--r--pykolab/logger.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/pykolab/logger.py b/pykolab/logger.py
index e1d1189..2101866 100644
--- a/pykolab/logger.py
+++ b/pykolab/logger.py
@@ -33,6 +33,7 @@ class Logger(logging.Logger):
loglevel capabilities, a debuglevel capability.
"""
debuglevel = 0
+ fork = False
loglevel = logging.CRITICAL
for arg in sys.argv:
@@ -40,6 +41,7 @@ class Logger(logging.Logger):
debuglevel = int(arg)
loglevel = logging.DEBUG
break
+
if '-d' == arg:
debuglevel = -1
continue
@@ -47,6 +49,10 @@ class Logger(logging.Logger):
if '-l' == arg:
loglevel = -1
continue
+
+ if '--fork' == arg:
+ fork = True
+
if loglevel == -1:
if hasattr(logging,arg.upper()):
loglevel = getattr(logging,arg.upper())
@@ -65,10 +71,11 @@ class Logger(logging.Logger):
plaintextformatter = logging.Formatter("%(asctime)s %(name)s %(levelname)s %(message)s")
- self.console_stdout = logging.StreamHandler(sys.stdout)
- self.console_stdout.setFormatter(plaintextformatter)
+ if not self.fork:
+ self.console_stdout = logging.StreamHandler(sys.stdout)
+ self.console_stdout.setFormatter(plaintextformatter)
- self.addHandler(self.console_stdout)
+ self.addHandler(self.console_stdout)
if kw.has_key('logfile'):
self.logfile = kw['logfile']
@@ -88,8 +95,9 @@ class Logger(logging.Logger):
pass
def remove_stdout_handler(self):
- self.console_stdout.close()
- self.removeHandler(self.console_stdout)
+ if not self.fork:
+ self.console_stdout.close()
+ self.removeHandler(self.console_stdout)
def debug(self, msg, level=1):
self.setLevel(self.loglevel)