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

2014-05-21 Thread Ben Nemec
On 05/21/2014 12: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

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

2014-05-21 Thread Johannes Erdfelt
On Wed, May 21, 2014, John Dennis wrote: > 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? It has been fixed, by making Python 3 :) This is a problem in the Pytho

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

2014-05-21 Thread John Dennis
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

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

2014-05-21 Thread Igor Kalnitsky
> 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): i

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

2014-05-21 Thread Doug Hellmann
On Thu, May 15, 2014 at 11:29 AM, Victor Stinner wrote: > 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#log

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

2014-05-19 Thread John Dennis
On 05/16/2014 09:11 AM, Johannes Erdfelt wrote: > six.text_type(exc) is the recommended solution. +1 -- John ___ OpenStack-dev mailing list OpenStack-dev@lists.openstack.org http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev

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

2014-05-19 Thread Igor Kalnitsky
*@Victor:* > " six.text_type(exc): always use Unicode. It may raise unicode error depending > on the exception, be careful. Example of such error in python 2: > unicode(Exception("nonascii:\xe9")). " It's very rare situation. Actually, it's no sense since we know nothing about exception's encodin

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

2014-05-17 Thread Johannes Erdfelt
On Fri, May 16, 2014, Igor Kalnitsky wrote: > > unicode(exc) (or six.text_type(exc)) works for all exceptions, built-in or > custom. > > That's too much of a statement. Sometimes exceptions implement their own > __str__ / __unitcode__ > methods, that return too many rubbish information or not eno

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

2014-05-17 Thread Johannes Erdfelt
On Fri, May 16, 2014, Victor Stinner wrote: > See my documentation: > https://wiki.openstack.org/wiki/Python3#logging_module_and_format_exceptions > > " six.text_type(exc): always use Unicode. It may raise unicode error > depending > on the exception, be careful. Example of such error in python

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

2014-05-16 Thread Joshua Harlow
- From: Victor Stinner Organization: eNovance Reply-To: "OpenStack Development Mailing List (not for usage questions)" Date: Friday, May 16, 2014 at 7:04 AM To: "OpenStack Development Mailing List (not for usage questions)" Subject: Re: [openstack-dev] [oslo] Logging exc

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

2014-05-16 Thread Victor Stinner
Le vendredi 16 mai 2014, 06:03:53 Johannes Erdfelt a écrit : > On Fri, May 16, 2014, Igor Kalnitsky wrote: > > > According to http://legacy.python.org/dev/peps/pep-0352/ the message > > > attribute of BaseException is deprecated since Python 2.6 and was > > > dropped in Python 3.0. > > > > Some p

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

2014-05-16 Thread Igor Kalnitsky
> unicode(exc) (or six.text_type(exc)) works for all exceptions, built-in or custom. That's too much of a statement. Sometimes exceptions implement their own __str__ / __unitcode__ methods, that return too many rubbish information or not enough. What do you do in that case? BTW, I don't say that

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

2014-05-16 Thread Johannes Erdfelt
On Thu, May 15, 2014, Victor Stinner wrote: > 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_fo

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

2014-05-16 Thread Johannes Erdfelt
On Fri, May 16, 2014, Igor Kalnitsky wrote: > > According to http://legacy.python.org/dev/peps/pep-0352/ the message > > attribute of BaseException is deprecated since Python 2.6 and was > > dropped in Python 3.0. > > Some projects have custom exception hierarchy, with strictly defined > attribut

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

2014-05-16 Thread Igor Kalnitsky
k.org> > Date: Thursday, May 15, 2014 at 2:20 PM > To: "OpenStack Development Mailing List (not for usage questions)" < > openstack-dev@lists.openstack.org> > Subject: Re: [openstack-dev] [oslo] Logging exceptions and Python 3 > >Hi, > > > Is

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

2014-05-15 Thread Joshua Harlow
v@lists.openstack.org>> Subject: Re: [openstack-dev] [oslo] Logging exceptions and Python 3 Hi, > Is there a reason to log the exception as Unicode on Python 2? Sure, why not? Some exceptions may have unicode message with non-ASCII characters. and we obviously can't cast such exceptio

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

2014-05-15 Thread Christian Berendt
On 05/15/2014 11:20 PM, Igor Kalnitsky wrote: > Example: > > LOG.error(e.message) According to http://legacy.python.org/dev/peps/pep-0352/ the message attribute of BaseException is deprecated since Python 2.6 and was dropped in Python 3.0. Christian. -- Christian Berendt Cloud Computing So

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

2014-05-15 Thread Igor Kalnitsky
Hi, > Is there a reason to log the exception as Unicode on Python 2? Sure, why not? Some exceptions may have unicode message with non-ASCII characters. and we obviously can't cast such exceptions with str() in Python 2.x. > The problem is that I don't know what is the best syntax to log excepti

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

2014-05-15 Thread Victor Stinner
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 kno