Added exception revision logging.

This commit is contained in:
Jeremy Fincher 2004-08-30 20:06:05 +00:00
parent 2faa09670a
commit 74763d4dec
2 changed files with 13 additions and 0 deletions

View File

@ -42,6 +42,7 @@ __all__ = []
exported = ['ignore', 'reversed', 'window', 'group',
'partition', 'any', 'all', 'rsplit']
import sys
import new
import string
string.ascii = string.maketrans('', '')
@ -196,6 +197,16 @@ import socket
# Some socket modules don't have sslerror, so we'll just make it an error.
if not hasattr(socket, 'sslerror'):
socket.sslerror = socket.error
# Trick to get an __revision__ attribute in all exceptions, if possible.
Exception__init__ = Exception.__init__
def __init__(self, *args, **kwargs):
caller = sys._getframe(1)
module = sys.modules.get(caller.f_globals.get('__name__'))
self.__revision__ = getattr(module, '__revision__', None)
Exception__init__(self, *args, **kwargs)
Exception.__init__ = __init__
for name in exported:
__builtins__[name] = globals()[name]

View File

@ -77,6 +77,8 @@ class Logger(logging.Logger):
eStrId = '%s:%s' % (E, path)
eId = hex(hash(eStrId) & 0xFFFFF)
logging.Logger.exception(self, *args)
if hasattr(e, '__revision__') and e.__revision__:
self.error('Exception __revision__: %r', e.__revision__)
self.error('Exception id: %s', eId)
# The traceback should be sufficient if we want it.
# self.error('Exception string: %s', eStrId)