[openstack-dev] Logging and traceback at same time.

Joshua Harlow harlowja at fastmail.com
Wed Feb 3 19:18:08 UTC 2016


Sean McGinnis wrote:
> On Wed, Feb 03, 2016 at 02:46:28PM +0800, 王华 wrote:
>> You can use LOG.exception.
>
> Yes, I highly recommend using LOG.exception in this case. That is
> exactly what it's used for. LOG.exception is pretty much exactly like
> LOG.error, but with the additional behavior that it will log out the
> details of whatever exception is currently in scope.

Not pretty much, it is ;)

https://hg.python.org/cpython/file/b4cbecbc0781/Lib/logging/__init__.py#l1305 


'''
def exception(self, msg, *args, **kwargs):
     kwargs['exc_info'] = True
     self.error(msg, *args, **kwargs)
'''

-Josh

>
>> Regards,
>> Wanghua
>>
>> On Wed, Feb 3, 2016 at 2:28 PM, Khayam Gondal<khayam.gondal at gmail.com>
>> wrote:
>>
>>> Is there a way to do logging the information and traceback at the same
>>> time. Currently I am doing it like this.
>>>
>>>
>>>
>>>
>>>
>>> LOG.error(_LE('Record already exists: %(exception)s '
>>>
>>>                       '\n %(traceback)'),
>>>
>>>                         {'exception': e1},
>>>
>>>                         {'traceback': traceback.print_stack()}).
>>>
>>>
>>>
>>> Let me know if this is correct way?
>>>
>>> Regards
>>>
>>> __________________________________________________________________________
>>> OpenStack Development Mailing List (not for usage questions)
>>> Unsubscribe: OpenStack-dev-request at lists.openstack.org?subject:unsubscribe
>>> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>>>
>>>
>
>> __________________________________________________________________________
>> OpenStack Development Mailing List (not for usage questions)
>> Unsubscribe: OpenStack-dev-request at lists.openstack.org?subject:unsubscribe
>> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
>
> __________________________________________________________________________
> OpenStack Development Mailing List (not for usage questions)
> Unsubscribe: OpenStack-dev-request at lists.openstack.org?subject:unsubscribe
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev



More information about the OpenStack-dev mailing list