On 05/21/2014 01:11 PM, Igor Kalnitsky wrote: >> So, write: >> >> LOG.debug(u'Could not do whatever you asked: %s', exc) >> >> or just: >> >> LOG.debug(exc) > > Actually, that's a bad idea to pass an exception instance to > some log function: LOG.debug(exc). Let me show you why. > > Here a snippet from logging.py: > > def getMessage(self): > if not _unicode: > msg = str(self.msg) > else: > msg = self.msg > if not isinstance(msg, basestring): > try: > msg = str(self.msg) > except UnicodeError: > msg = self.msg # we keep exception object as it is > if self.args: # this condition is obviously False > msg = msg % self.args > return msg # returns an exception object, not a > text > > And here another snippet from the format() method: > > record.message = record.getMessage() > # ... some time formatting ... > s = self._fmt % record.__dict__ # FAIL > > the old string formatting will call str(), not unicode() and we will FAIL > with UnicodeEncodeError.
But that's a bug in the logging implementation. Are we supposed to write perverse code just to avoid coding mistakes in other modules? Why not get the fundamental problem fixed? -- John _______________________________________________ OpenStack-dev mailing list OpenStack-dev@lists.openstack.org http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev