From f718919c459be88d24fbf96a97856835c611b7a8 Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Fri, 28 Aug 2015 08:47:23 -0500 Subject: [PATCH] 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 --- doc/source/usage.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/source/usage.rst b/doc/source/usage.rst index e544d3c0..29fd4785 100644 --- a/doc/source/usage.rst +++ b/doc/source/usage.rst @@ -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