diff --git a/pykolab/imap/cyrus.py b/pykolab/imap/cyrus.py --- a/pykolab/imap/cyrus.py +++ b/pykolab/imap/cyrus.py @@ -90,6 +90,7 @@ if conf.debuglevel > 8: self.VERBOSE = True self.m.debug = 5 + self.LOGFD = pykolab.logger.StderrToLogger(log) # Initialize our variables self.separator = self.SEP @@ -139,7 +140,13 @@ Login to the Cyrus IMAP server through cyruslib.CYRUS, but set our hierarchy separator. """ - cyruslib.CYRUS.login(self, *args, **kw) + try: + cyruslib.CYRUS.login(self, *args, **kw) + except cyruslib.CYRUSError, errmsg: + log.error("Login to Cyrus IMAP server failed: %r", errmsg) + except: + log.exception(errmsg) + self.separator = self.SEP try: self._id() diff --git a/pykolab/logger.py b/pykolab/logger.py --- a/pykolab/logger.py +++ b/pykolab/logger.py @@ -27,6 +27,22 @@ from pykolab.translate import _ +class StderrToLogger(object): + """ + Fake file-like stream object that redirects writes to a logger instance. + """ + def __init__(self, logger, log_level=logging.DEBUG): + self.logger = logger + self.log_level = log_level + self.linebuf = '' + + def write(self, buf): + for line in buf.rstrip().splitlines(): + self.logger.log(self.log_level, line.rstrip()) + + def flush(self): + pass + class Logger(logging.Logger): """ The PyKolab version of a logger. diff --git a/wallace/modules.py b/wallace/modules.py --- a/wallace/modules.py +++ b/wallace/modules.py @@ -20,7 +20,6 @@ import os import sys import time -import traceback from email import message_from_string from email.message import Message @@ -130,6 +129,10 @@ def _sendmail(sender, recipients, msg): # NOTE: Use "127.0.0.1" here for IPv6 (see also the service # definition in master.cf). + + sl = pykolab.logger.StderrToLogger(log) + smtplib.stderr = sl + smtp = smtplib.SMTP("127.0.0.1", 10027) if conf.debuglevel > 8: @@ -169,8 +172,7 @@ log.error("SMTP Sender Refused, %r" % (errmsg)) except Exception, errmsg: - log.error(_("Unknown error occurred; %r") % (errmsg)) - log.error("%r" % (traceback.format_exc())) + log.exception(_("Unknown error occurred: %r") % (errmsg)) return False