[openstack-dev] [oslo] Logging exceptions and Python 3

Victor Stinner victor.stinner at enovance.com
Thu May 15 15:29:17 UTC 2014


Hi,

I'm trying to define some rules to port OpenStack code to Python 3. I just 
added a section in the "Port Python 2 code to Python 3" about formatting 
exceptions and the logging module:
https://wiki.openstack.org/wiki/Python3#logging_module_and_format_exceptions

The problem is that I don't know what is the best syntax to log exceptions. 
Some projects convert the exception to Unicode, others use str(). I also saw 
six.u(str(exc)) which is wrong IMO (it can raise unicode error if the message 
contains a non-ASCII character).

IMO the safest option is to use str(exc). For example, use 
LOG.debug(str(exc)).

Is there a reason to log the exception as Unicode on Python 2?

Victor



More information about the OpenStack-dev mailing list