Good suggestion.
What I ended up doing was writing my own tiny logging handler and adding
it to the root logger.
In the handler's 'handle' method, I look for the text 'Uncaught
exception'. If it's there, that log record has everything I need,
including the exception record.
From that I can compose an email/SMS/etc and send it out.
Of course, this is a little brittle since it depends on 'Uncaught
exception', but that's easily managed, I think.
Thanks for the suggestions!
class LoggingHandler(Handler):
"""
This is our logging handler. It's whole purpose in life is to look
for severe
errors, and if it sees one, make the appropriate notifications.
"""
def __init__(self):
print "LoggingHandler::__init__"
def handle(self, record):
"""
"""
msg = None
if record != None:
msg = record.getMessage()
if msg.startswith('Uncaught exception') != True:
return
# Extract the interesting bits
(type, value, tb) = record.exc_info
amazonSes = AmazonSES(amazon_ses_AccessKeyID,
amazon_ses_SecretAccessKey)
message = EmailMessage()
message.subject = "Service Failure "
message.bodyText = "Service Failure detected ' + \
strftime("%Y-%m-%d %H:%M:%S", gmtime()) + ' GMT' + \
', ' + strftime("%Y-%m-%d %H:%M:%S", localtime()) + ' Local' + \
'\r\n\r\n'
message.bodyText += 'Message: ' + msg + '\r\n\r\n'
if tb != None:
message.bodyText += 'Exception: ' + '\r\n\r\n'
for tb_line in traceback.format_exception(type, value, tb):
message.bodyText += tb_line + '\r\n'
fromEmailAddress = 'no-r...@service.com'
toEmailAddress = 'vic...@service.com'
try:
result = amazonSes.sendEmail(str(fromEmailAddress),
str(toEmailAddress),
message, replyToAddresses=str(fromEmailAddress))
except AmazonError, e:
print "LoggingHandler::handle Uncaught Error sending email to " +
repr(toEmailAddress) + \
", errorType " + repr(e.errorType) + \
", code " + repr(e.code) + \
", message " + repr(e.message)
return
except:
print "LoggingHandler::handle Uncaught Error sending email to " +
repr(toEmailAddress) + \
", Exception " + repr(sys.exc_info()[0])
return
print "LoggingHandler::handle Result.requestId " +
repr(result.requestId) + \
", result.messageId " + repr(result.messageId)
print "LoggingHandler::handle Message: " + msg