[issue1295] logging records cache the result of formatException()

2008-01-21 Thread Vinay Sajip

Vinay Sajip added the comment:

I've updated the docs (Formatter.format) to mention the caching and its
effect on multiple formatters.

--
nosy: +vsajip

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1295
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1295] logging records cache the result of formatException()

2007-10-18 Thread Thomas Heller

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



[issue1295] logging records cache the result of formatException()

2007-10-18 Thread Guido van Rossum

Guido van Rossum added the comment:

This is tough. On the one hand you are right that different classes that
have different formatException() methods aren't treated correctly; on
the other hand I think the caching is important for other cases where
there are multiple loggers all using the default formatException().

I recommend that instead of getting rid of the cache, you fix your class
by overriding format() to reset record.ex c_text and then calling the
base class format() method.

--
nosy: +gvanrossum

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1295
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1295] logging records cache the result of formatException()

2007-10-18 Thread Thomas Heller

Thomas Heller added the comment:

  This is tough. On the one hand you are right that different classes that
  have different formatException() methods aren't treated correctly; on
  the other hand I think the caching is important for other cases where
  there are multiple loggers all using the default formatException().
  
  I recommend that instead of getting rid of the cache, you fix your class
  by overriding format() to reset record.ex c_text and then calling the
  base class format() method.

That is what I have been doing although I think that I have to reset
record.exc_text also AFTER the call to format() for the following
handlers, if any.

So, should this issue be closed as 'wont fix' ?

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1295
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1295] logging records cache the result of formatException()

2007-10-18 Thread Thomas Heller

Thomas Heller added the comment:

I think that a warning or an example in the docs would be nice, but I
have no time to make a patch for that.

--
resolution:  - wont fix
status: open - closed

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1295
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1295] logging records cache the result of formatException()

2007-10-18 Thread Guido van Rossum

Guido van Rossum added the comment:

I think so.

On 10/18/07, Thomas Heller [EMAIL PROTECTED] wrote:

 Thomas Heller added the comment:

   This is tough. On the one hand you are right that different classes that
   have different formatException() methods aren't treated correctly; on
   the other hand I think the caching is important for other cases where
   there are multiple loggers all using the default formatException().
  
   I recommend that instead of getting rid of the cache, you fix your class
   by overriding format() to reset record.ex c_text and then calling the
   base class format() method.

 That is what I have been doing although I think that I have to reset
 record.exc_text also AFTER the call to format() for the following
 handlers, if any.

 So, should this issue be closed as 'wont fix' ?

 __
 Tracker [EMAIL PROTECTED]
 http://bugs.python.org/issue1295
 __


__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1295
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com