On Wed, Oct 6, 2010 at 6:46 PM, Luke Plant <[email protected]> wrote: > On Wed, 2010-10-06 at 12:24 +0800, Russell Keith-Magee wrote: > >> Monkeypatching isn't a particularly attractive option to me - there's >> just too much . >> >> A fourth option would be to include Python's logging module, much as >> we do with doctest, simpleJSON, and we're about to do with unittest2. >> It's a heavyweight option, but it would do the job. We could remove >> the inclusion once we drop Python 2.4 support (possibly in Django >> 1.4). >> >> A fifth option would be to catch the error cases and wrap them in a >> backwards compatibility layer: >> >> try: >> logging.error('error message', extra={'foo': bar}) >> except TypeError: >> logging.error('error message') > > Since we always do 'logger = logging.getLogger' and then 'logger.error', > rather than 'logging.error', there is another option: we provide our own > 'getLogger' function that is just logging.getLogger for Python 2.5 and > later, and simple wrapper for Python 2.4. > > Then we only need to be change the imports and the 'getLogger' call when > we drop Python 2.4 support. A patch is attached that seems to work - > the entire test suite passes under 2.4. This method won't give any > overhead for Python 2.5, unlike the try/except method which does add a > little overhead.
That approach works (as in - it doesn't raise errors), but it means that under Python 2.4, you lose any of the "extra" data. In particular, it means that * it's really hard to do anything interesting with the 4XX series errors, * the HTTP 500 error emails won't have any details about the request that caused them * the DB logging calls won't include any details about the SQL that was being logged. Now, one possibility is to say "Suck it up and upgrade your Python version", but I'd rather consider that as a last resort. Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
