summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-05-31 14:45:14 +0200
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-05-31 14:45:46 +0200
commit87699bf132a9166d16bdc0ac57a887f66316b3bc (patch)
tree212c7db4c17bdfd082ed69a19f525d37830bd212
parent9efaf737a917885ff98485a07b01cf339ccdd159 (diff)
downloadpykolab-87699bf132a9166d16bdc0ac57a887f66316b3bc.tar.gz
Attempt to append to the log file, escape permission errors on log file
-rw-r--r--pykolab/logger.py34
1 files changed, 19 insertions, 15 deletions
diff --git a/pykolab/logger.py b/pykolab/logger.py
index 878f79f..a0c75c9 100644
--- a/pykolab/logger.py
+++ b/pykolab/logger.py
@@ -84,13 +84,6 @@ class Logger(logging.Logger):
else:
self.logfile = '/var/log/kolab/pykolab.log'
- # Make sure the log file exists
- fhandle = file(self.logfile, 'a')
- try:
- os.utime(self.logfile, None)
- finally:
- fhandle.close()
-
# Make sure (read: attempt to change) the permissions
try:
(ruid, euid, suid) = os.getresuid()
@@ -113,17 +106,28 @@ class Logger(logging.Logger):
self.logfile
)
+ # Make sure the log file exists
try:
- filelog_handler = logging.FileHandler(filename=self.logfile)
- filelog_handler.setFormatter(plaintextformatter)
- except IOError, e:
- print >> sys.stderr, _("Cannot log to file %s: %s") % (self.logfile, e)
+ fhandle = file(self.logfile, 'a')
+ try:
+ os.utime(self.logfile, None)
+ finally:
+ fhandle.close()
- if not len(self.handlers) > 1:
try:
- self.addHandler(filelog_handler)
- except:
- pass
+ filelog_handler = logging.FileHandler(filename=self.logfile)
+ filelog_handler.setFormatter(plaintextformatter)
+ except IOError, e:
+ print >> sys.stderr, _("Cannot log to file %s: %s") % (self.logfile, e)
+
+ if not len(self.handlers) > 1:
+ try:
+ self.addHandler(filelog_handler)
+ except:
+ pass
+
+ except IOError, errmsg:
+ pass
def remove_stdout_handler(self):
if not self.fork: