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

_______________________________________________
OpenStack-dev mailing list
OpenStack-dev@lists.openstack.org
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev

Reply via email to