def my_log_traceback(severity=logging.CRITICAL): """Write the last error's traceback to the cherrypy error log.""" from cherrypy import _cperror h = [" %s: %s" % (k, v) for k, v in cherrypy.request.header_list] cherrypy.log('\nRequest Headers:\n' + '\n'.join(h) + '\n\n' + _cperror.format_exc(), "HTTP", severity=severity) cherrypy.tools.my_log_tracebacks = cherrypy.Tool('before_error_response', my_log_traceback) from logging import handlers h = handlers.SMTPHandler('localhost', 'root@localhost', 'root@localhost', 'CherryPy Error Log Entry') h.setLevel(logging.CRITICAL) cherrypy.log.error_log.addHandler(h)