From: Adrian Likins Date: Thu, 12 Feb 2009 20:08:59 +0000 (-0500) Subject: add a excepthook handler for uncaught exceptions, so they get written to the log X-Git-Tag: v0.25~16 X-Git-Url: https://pwan.org/git/?a=commitdiff_plain;h=ed20b2fa1f9e733e24a17c7983d5b411623c4ecc;p=certmaster.git add a excepthook handler for uncaught exceptions, so they get written to the log https://fedorahosted.org/func/ticket/70 --- diff --git a/certmaster/certmaster.py b/certmaster/certmaster.py index e4a3d17..506a029 100644 --- a/certmaster/certmaster.py +++ b/certmaster/certmaster.py @@ -16,7 +16,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # standard modules import SimpleXMLRPCServer +import string import sys +import traceback import os import os.path from OpenSSL import crypto @@ -323,9 +325,24 @@ def serve(xmlrpcinstance): xmlrpcinstance.audit_logger.logger.info("certmaster started") server.serve_forever() +def excepthook(exctype, value, tracebackobj): + exctype_blurb = "Exception occured: %s" % exctype + excvalue_blurb = "Exception value: %s" % value + exctb_blurb = "Exception Info:\n%s" % string.join(traceback.format_list(traceback.extract_tb(tracebackobj))) + + print exctype_blurb + print excvalue_blurb + print exctb_blurb + + log = logger.Logger().logger + log.info(exctype_blurb) + log.info(excvalue_blurb) + log.info(exctb_blurb) + def main(argv): - + + sys.excepthook = excepthook cm = CertMaster('/etc/certmaster/certmaster.conf') if "daemon" in argv or "--daemon" in argv: