New submission from Thomas Heller:
I needed two logging handlers in my application, one notifiying the user
of errors, the other writing errors to a logfile. So I created a custom
subclass of logging.Formatter and redefined the formatException() method
that returned a summary of the exception like 'ZeroDivisionError'
instead of the full traceback.
Unfortunately the logging record caches the result of the
handler.formatException() call in the exc_text variable, and the
formatException() method of the second handler isn't called at all.
The attached patch removes the caching and fixes the problem.
----------
components: Library (Lib)
files: logging.patch
keywords: patch
messages: 56525
nosy: theller
severity: normal
status: open
title: logging records cache the result of formatException()
type: behavior
versions: Python 2.4, Python 2.5, Python 2.6, Python 3.0
Added file: http://bugs.python.org/file8563/logging.patch
__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1295>
__________________________________
Index: Lib/logging/__init__.py
===================================================================
--- Lib/logging/__init__.py (revision 58033)
+++ Lib/logging/__init__.py (working copy)
@@ -247,7 +247,6 @@
self.filename = pathname
self.module = "Unknown module"
self.exc_info = exc_info
- self.exc_text = None # used to cache the traceback text
self.lineno = lineno
self.funcName = func
self.created = ct
@@ -420,14 +419,10 @@
record.asctime = self.formatTime(record, self.datefmt)
s = self._fmt % record.__dict__
if record.exc_info:
- # Cache the traceback text to avoid converting it multiple times
- # (it's constant anyway)
- if not record.exc_text:
- record.exc_text = self.formatException(record.exc_info)
- if record.exc_text:
+ exc_text = self.formatException(record.exc_info)
if s[-1:] != "\n":
s = s + "\n"
- s = s + record.exc_text
+ s = s + exc_text
return s
#
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com