unify exception logging

This commit is contained in:
Frédéric Péters 2012-08-16 10:21:45 +02:00
parent 166bbaa265
commit 708e9edab8
4 changed files with 35 additions and 44 deletions

View File

@ -35,6 +35,14 @@ class CmdProcessBounce(Command):
import publisher
try:
publisher.WcsPublisher.configure(self.config, sub_options.extra)
pub = publisher.WcsPublisher.create_publisher()
pub.app_dir = os.path.join(pub.app_dir, server_part)
except:
# not much we can do if we don't have a publisher object :/
return
try:
parser = email.Parser.Parser()
bouncers_dir = os.path.join(os.path.dirname(__file__), 'Bouncers')
@ -57,10 +65,6 @@ class CmdProcessBounce(Command):
except (IndexError, KeyError):
return
publisher.WcsPublisher.configure(self.config, sub_options.extra)
pub = publisher.WcsPublisher.create_publisher()
pub.app_dir = os.path.join(pub.app_dir, server_part)
try:
token = Token.get(token_id)
except KeyError:
@ -79,9 +83,8 @@ class CmdProcessBounce(Command):
bounce.original_rcpts = token.email_rcpts
bounce.email_type = token.email_type
bounce.store()
except Exception, e:
import traceback
file('/tmp/bounces-error', 'a+').write(traceback.format_exc())
except:
pub.notify_of_exception(sys.exc_info(), context='[BOUNCE]')
sys.exit(1)
CmdProcessBounce.register()

View File

@ -82,23 +82,7 @@ def cron(publisher):
try:
job.function(publisher)
except:
(exc_type, exc_value, tb) = sys.exc_info()
error_summary = traceback.format_exception_only(exc_type, exc_value)
error_summary = '[CRON] ' + error_summary[0][0:-1] # de-listify and strip newline
plain_error_msg = publisher._generate_plaintext_error(
None,
None,
exc_type, exc_value,
tb)
try:
publisher.logger.log_internal_error(error_summary, plain_error_msg)
except socket.error:
# will happen if there is no mail server available and exceptions
# were configured to be mailed.
pass
except OSError:
# this could happen on file descriptor exhaustion
pass
get_publisher().notify_of_exception(sys.exc_info(), context='[CRON]')
time.sleep(10)

View File

@ -129,26 +129,7 @@ class HTTPResponse(quixote.http_response.HTTPResponse):
try:
job_function(job=job)
except:
(exc_type, exc_value, tb) = sys.exc_info()
error_summary = traceback.format_exception_only(exc_type, exc_value)
error_summary = error_summary[0][0:-1] # de-listify and strip newline
plain_error_msg = get_publisher()._generate_plaintext_error(
get_request(),
self,
exc_type, exc_value,
tb)
try:
get_publisher().logger.log_internal_error(error_summary, plain_error_msg)
except socket.error:
# will happen if there is no mail server available and exceptions
# were configured to be mailed.
pass
except OSError:
# this could happen on file descriptor exhaustion
pass
get_publisher().notify_of_exception(sys.exc_info())
job.exception = traceback.format_exc()
job.status = N_('failed')
else:

View File

@ -210,6 +210,29 @@ class QommonPublisher(Publisher):
return error_file.getvalue()
def notify_of_exception(self, exc_tuple, context=None):
exc_type, exc_value, tb = exc_tuple
error_summary = traceback.format_exception_only(exc_type, exc_value)
error_summary = error_summary[0][0:-1] # de-listify and strip newline
if context:
error_summary = '%s %s' % (context, error_summary)
plain_error_msg = self._generate_plaintext_error(
get_request(),
self,
exc_type, exc_value,
tb)
try:
self.logger.log_internal_error(error_summary, plain_error_msg)
except socket.error:
# will happen if there is no mail server available and exceptions
# were configured to be mailed.
pass
except OSError:
# this could happen on file descriptor exhaustion
pass
def finish_failed_request(self):
# duplicate at lot from parent class, just to use our own HTTPResponse
request = get_request()