This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2007年10月18日 15:30 by theller, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| logging.patch | theller, 2007年10月18日 15:30 | |||
| Messages (6) | |||
|---|---|---|---|
| msg56525 - (view) | Author: Thomas Heller (theller) * (Python committer) | Date: 2007年10月18日 15:30 | |
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. |
|||
| msg56530 - (view) | Author: Guido van Rossum (gvanrossum) * (Python committer) | Date: 2007年10月18日 17:01 | |
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. |
|||
| msg56536 - (view) | Author: Thomas Heller (theller) * (Python committer) | Date: 2007年10月18日 17:49 | |
> > 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' ? |
|||
| msg56537 - (view) | Author: Guido van Rossum (gvanrossum) * (Python committer) | Date: 2007年10月18日 17:53 | |
I think so. On 10/18/07, Thomas Heller <report@bugs.python.org> 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 <report@bugs.python.org> > <http://bugs.python.org/issue1295> > __________________________________ > |
|||
| msg56538 - (view) | Author: Thomas Heller (theller) * (Python committer) | Date: 2007年10月18日 18:03 | |
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. |
|||
| msg61430 - (view) | Author: Vinay Sajip (vinay.sajip) * (Python committer) | Date: 2008年01月21日 17:55 | |
I've updated the docs (Formatter.format) to mention the caching and its effect on multiple formatters. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:27 | admin | set | github: 45636 |
| 2008年01月21日 17:55:15 | vinay.sajip | set | nosy:
+ vinay.sajip messages: + msg61430 |
| 2007年10月18日 18:03:20 | theller | set | status: open -> closed resolution: wont fix messages: + msg56538 |
| 2007年10月18日 17:53:25 | gvanrossum | set | messages: + msg56537 |
| 2007年10月18日 17:49:35 | theller | set | messages: + msg56536 |
| 2007年10月18日 17:01:37 | gvanrossum | set | nosy:
+ gvanrossum messages: + msg56530 |
| 2007年10月18日 15:30:36 | theller | create | |