Fix poor examples of exception logging
There were several examples showing passing an exception in as the message text to a call to LOG.exception. LOG.exception will automatically log the exception details, so doing something like this results in the exception information being written out twice. To prevent the possibility of someone seeing these examples and assuming that is the correct way to use LOG.exception, examples have been updated to use LOG.error instead to illustrate the correct way to pass in exceptions in the message string. Change-Id: I582008609180a02eaff3d85bee5b5ca4381719ce
This commit is contained in:
parent
8ab7644d57
commit
f718919c45
@ -87,7 +87,7 @@ format strings therefore need to be passed as unicode objects --
|
||||
that's strictly :class:`unicode`, not :class:`str`. If a message has
|
||||
no interpolation for extra parameters, a byte string can be used.
|
||||
|
||||
The most common place to encounter this is where :meth:`Logger.exception`
|
||||
The most common place to encounter this is where :meth:`Logger.error`
|
||||
is used by passing an exception object as the first argument.
|
||||
|
||||
::
|
||||
@ -96,7 +96,7 @@ is used by passing an exception object as the first argument.
|
||||
try:
|
||||
do_something()
|
||||
except Exception as err:
|
||||
LOG.exception(err)
|
||||
LOG.error(err)
|
||||
|
||||
Now, the error should be converted to unicode either by calling
|
||||
:func:`six.text_type` or by using a unicode formatting string to
|
||||
@ -117,14 +117,14 @@ produced by passing the exception with a useful message.
|
||||
try:
|
||||
do_something()
|
||||
except Exception as err:
|
||||
LOG.exception(_LE(u"do_something couldn't do something: %s"), err)
|
||||
LOG.error(_LE(u"do_something couldn't do something: %s"), err)
|
||||
|
||||
# New style, alternate without context
|
||||
import six
|
||||
try:
|
||||
do_something()
|
||||
except Exception as err:
|
||||
LOG.exception(six.text_type(err))
|
||||
LOG.error(six.text_type(err))
|
||||
|
||||
Failure to do this for exceptions or other objects containing
|
||||
translatable strings from ``oslo.i18n`` results in an exception when
|
||||
|
Loading…
x
Reference in New Issue
Block a user