[Checkins]
SVN: zope.exceptions/branches/aaron-traceback-log-formatting/src/zope/exceptions/
Log formatter now formats exceptions itself,
rather than needing them to be
Aaron Lehmann
aaron at zope.com
Sat Dec 29 16:32:40 EST 2007
Log message for revision 82556:
Log formatter now formats exceptions itself, rather than needing them to be
provided in the message.
Changed:
U zope.exceptions/branches/aaron-traceback-log-formatting/src/zope/exceptions/log.py
U zope.exceptions/branches/aaron-traceback-log-formatting/src/zope/exceptions/tests/test_exceptionformatter.py
-=-
Modified: zope.exceptions/branches/aaron-traceback-log-formatting/src/zope/exceptions/log.py
===================================================================
--- zope.exceptions/branches/aaron-traceback-log-formatting/src/zope/exceptions/log.py 2007-12-29 17:12:17 UTC (rev 82555)
+++ zope.exceptions/branches/aaron-traceback-log-formatting/src/zope/exceptions/log.py 2007-12-29 21:32:39 UTC (rev 82556)
@@ -21,7 +21,7 @@
from zope.exceptions.exceptionformatter import print_exception
class Formatter(logging.Formatter):
- def __init__(self, as_html=0, fmt=None, datefmt=None):
+ def __init__(self, fmt=None, datefmt=None, as_html=0,):
logging.Formatter.__init__(self, fmt=fmt, datefmt=datefmt)
self.as_html = as_html
@@ -41,9 +41,14 @@
if not record.exc_text:
record.exc_text = self.formatException(record.exc_info, record=record)
if record.exc_text:
- if s[-1] != "\n":
- s = s + "\n"
- s = s + record.exc_text
+ s = record.exc_text
+ else:
+ cdict = record.__dict__.copy()
+ lines = []
+ for line in record.message.splitlines():
+ cdict['message'] = line
+ lines.append(self._fmt % cdict)
+ s = '\n'.join(lines)
return s
def formatException(self, ei, record=None):
Modified: zope.exceptions/branches/aaron-traceback-log-formatting/src/zope/exceptions/tests/test_exceptionformatter.py
===================================================================
--- zope.exceptions/branches/aaron-traceback-log-formatting/src/zope/exceptions/tests/test_exceptionformatter.py 2007-12-29 17:12:17 UTC (rev 82555)
+++ zope.exceptions/branches/aaron-traceback-log-formatting/src/zope/exceptions/tests/test_exceptionformatter.py 2007-12-29 21:32:39 UTC (rev 82556)
@@ -25,7 +25,7 @@
import logging
import StringIO
-def tb(as_html=0, format=None, exc=None,):
+def tb(as_html=0, format=None):
log = logging.getLogger('')
fake_stdout = StringIO.StringIO()
hndler = logging.StreamHandler(fake_stdout)
@@ -34,10 +34,7 @@
t, v, b = sys.exc_info()
try:
- if exc:
- log.exception(exc.msg)
- else:
- log.exception(''.join(format_exception(t, v, b, as_html=as_html)))
+ log.exception('')
s = fake_stdout.getvalue()
return s
finally:
@@ -179,7 +176,7 @@
try:
exec 'syntax error'
except SyntaxError, se:
- s = tb(exc=se, format="Hello, World! %(message)s")
+ s = tb(format="Hello, World! %(message)s")
# Hello, World! Traceback (most recent call last):
# Hello, World! Module zope.exceptions.tests.test_exceptionformatter, line ??, in testFormattedExceptionText
# Hello, World! exec \'syntax error\'
@@ -196,14 +193,16 @@
try:
exec 'syntax error'
except SyntaxError, se:
- s = tb(as_html=1, exc=se, format="Hello, World! %(message)s")
- # Hello, World! Traceback (most recent call last):
- # Hello, World! Module zope.exceptions.tests.test_exceptionformatter, line ??, in testFormattedExceptionHTML
- # Hello, World! exec \'syntax error\'
- # Hello, World! File "<string>", line 1
- # Hello, World! syntax error
- # Hello, World! ^
- # Hello, World! SyntaxError: unexpected EOF while parsing
+ s = tb(as_html=1, format="Hello, World! %(message)s")
+ # <p>Hello, World! Traceback (most recent call last):
+ # <ul>
+ # <li>Hello, World! File "/Users/aaron/work/projects/zope.exceptions-traceback-log-formatting/src/zope/exceptions/tests/test_exceptionformatter.py", line 197, in testFormattedExceptionHTML<br />
+ # Hello, World! exec 'syntax error'</li>
+ # </ul>Hello, World! File "<string>", line 1<br />
+ # Hello, World! syntax error<br />
+ # Hello, World! ^<br />
+ # Hello, World! SyntaxError: unexpected EOF while parsing<br />
+ # </p>
self.assertEquals(s.splitlines()[-4:],
['Hello, World! syntax error<br />',
'Hello, World! ^<br />',
More information about the Checkins
mailing list