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.

Author vinay.sajip
Recipients Kronuz, docs@python, eric.araujo, ezio.melotti, vinay.sajip
Date 2013-02-08.23:07:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1360364842.04.0.471800306433.issue17155@psf.upfronthosting.co.za>
In-reply-to
Content
It is by design that logging accepts arbitrary objects, rather than just strings, see

docs.python.org/howto/logging.html#arbitrary-object-messages

and, as documented, the instance's __str__ will be called by logging calling str() on the instance. If people are being lazy and doing logging.exception(exc) where exc is an exception instance, then they need to change their code. Recall that on Python 2.x, just doing a + b can trigger a UnicodeError because of implicit bytes->Unicode conversions which use ASCII as a default (this is just how Python 2.x works - nothing to do with logging). An arbitrary exception's str() method may or may not be smart with respect to this sort of behaviour. I think the answer is for people to be more aware of Unicode issues and how Python 2.x deals with mixed Unicode and byte data. If the _fmt string you are referring to is the Formatter instance attribute, you can control that by passing whatever you want to the Formatter - a Unicode string, if you wish.

The normal logging exception handling is as per Éric's example (though of course you can have placeholders and arguments passed to the exception call, as in

    logger.exception('Problem with %r', 'specific data')

I'm closing as invalid, because the example you quoted as working is how people are supposed to use it.
History
Date User Action Args
2013-02-08 23:07:22vinay.sajipsetrecipients: + vinay.sajip, ezio.melotti, eric.araujo, docs@python, Kronuz
2013-02-08 23:07:22vinay.sajipsetmessageid: <1360364842.04.0.471800306433.issue17155@psf.upfronthosting.co.za>
2013-02-08 23:07:22vinay.sajiplinkissue17155 messages
2013-02-08 23:07:21vinay.sajipcreate