Dang - accidentally hit send. Let's try that again.

2010/10/6 Russell Keith-Magee <russ...@keith-magee.com>:
> 2010/10/6 Łukasz Rekucki <lreku...@gmail.com>:
>> Hi,
>>
>> I'm getting a whole bunch of errors related to logging on Python 2.4::
>>
>> ERROR: Missing templates are correctly reported by test client
>> ----------------------------------------------------------------------
>> Traceback (most recent call last):
>>  File 
>> "/home/lrekucki/projekty/django/django_trunk/tests/regressiontests/test_client_regress/models.py",
>> line 583, in test_no_404_template
>>    response = self.client.get("/no_such_view/")
>>  File "/home/lrekucki/projekty/django/django_trunk/django/test/client.py",
>> line 298, in get
>>    response = self.request(**r)
>>  File "/home/lrekucki/projekty/django/django_trunk/django/test/client.py",
>> line 238, in request
>>    response = self.handler(environ)
>>  File "/home/lrekucki/projekty/django/django_trunk/django/test/client.py",
>> line 79, in __call__
>>    response = self.get_response(request)
>>  File 
>> "/home/lrekucki/projekty/django/django_trunk/django/core/handlers/base.py",
>> line 139, in get_response
>>    return self.handle_uncaught_exception(request, resolver, sys.exc_info())
>>  File 
>> "/home/lrekucki/projekty/django/django_trunk/django/core/handlers/base.py",
>> line 182, in handle_uncaught_exception
>>    extra={
>>  File "/home/lrekucki/python/plain2.4//lib/python2.4/logging/__init__.py",
>> line 999, in error
>>    apply(self._log, (ERROR, msg, args), kwargs)
>> TypeError: _log() got an unexpected keyword argument 'extra'
>>
>> Sadly, it's true - log functions don't have extra=* in Python 2.4[1].
>> Possible solutions I can see right now:
>>
>>  * revert the logging patch (that would be quite bad)
>>  * try to do some ugly monkey patching to the logging module
>>  * drop Python 2.4 support
>>
>> Opinions ?

I shall now sing a selection of arias from the opera I have written,
entitled "Oh crap and buggery".

:-)

Dropping Python 2.4 would be the easiest solution, but as I've
commented previously, it really isn't an option. I really don't want
to revert logging -- the set of cases where it's useful vastly exceeds
the cases where it isn't.

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')

The downside of this simple approach is that the handlers that need
status_code, request, and all the other useful details won't be able
to access them.

I haven't full investigated the options here, but we *might* be able
to do some fiddling with exc_info to work around this. If we mark a
logging call as exc_info=1, the stack frame is passed to the logging
handler; in cases where extra isn't available, we may be able to put
the variables we want into locals on the top stack frame, and check
for them when needed. It's a messy workaround, but it might just work
-- and then we can get rid of it as soon as we've dumped Python 2.4.

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 django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to