Better traceback handling.

This commit is contained in:
Jeremy Fincher 2004-04-22 21:34:40 +00:00
parent bd1dedb8e9
commit c63826dcff

View File

@ -39,6 +39,8 @@ __revision__ = "$Id$"
import plugins import plugins
import logging import logging
import os.path
from itertools import imap
import log import log
import conf import conf
@ -59,6 +61,7 @@ class IrcHandler(logging.Handler):
s = utils.normalizeWhitespace(self.format(record)) s = utils.normalizeWhitespace(self.format(record))
except: except:
self.handleError(record) self.handleError(record)
return
for target in config.targets(): for target in config.targets():
msgmaker = ircmsgs.privmsg msgmaker = ircmsgs.privmsg
if config.notice() and not ircutils.isChannel(target): if config.notice() and not ircutils.isChannel(target):
@ -94,14 +97,19 @@ class IrcHandler(logging.Handler):
class IrcFormatter(log.Formatter): class IrcFormatter(log.Formatter):
def formatException(self, ei): def formatException(self, (E, e, tb)):
import cStringIO L = [utils.exnToString(e), '::']
import traceback while tb:
sio = cStringIO.StringIO() lineno = tb.tb_lineno
traceback.print_exception(ei[0], ei[1], None, None, sio) code = tb.tb_frame.f_code
s = sio.getvalue() function = code.co_name
sio.close() filename = os.path.basename(code.co_filename)
return s L.append('[%s|%s|%s]' % (filename, function, lineno))
tb = tb.tb_next
del tb
while sum(imap(len, L)) > 425:
L.pop()
return ' '.join(L)
class ColorizedIrcFormatter(IrcFormatter): class ColorizedIrcFormatter(IrcFormatter):
@ -117,9 +125,9 @@ class ColorizedIrcFormatter(IrcFormatter):
s = IrcFormatter.format(self, record, *args, **kwargs) s = IrcFormatter.format(self, record, *args, **kwargs)
if conf.supybot.plugins.LogToIrc.colorized(): if conf.supybot.plugins.LogToIrc.colorized():
if record.levelno == logging.CRITICAL: if record.levelno == logging.CRITICAL:
s = ircutils.bold(ircutils.mircColor(s, fg='red')) s = ircutils.bold(ircutils.bold(s))
elif record.levelno == logging.ERROR: elif record.levelno == logging.ERROR:
s = ircutils.mircColor(s, fg='orange') s = ircutils.mircColor(s, fg='red')
elif record.levelno == logging.WARNING: elif record.levelno == logging.WARNING:
s = ircutils.mircColor(s, fg='yellow') s = ircutils.mircColor(s, fg='yellow')
return s return s