From 3c0289844f73b9e685b8443c90b0ca80e0b18f28 Mon Sep 17 00:00:00 2001 From: Joel Wright Date: Sun, 5 Apr 2015 16:48:34 +0100 Subject: Log and report trace on service operation fails This patch adds exception logging to the swift service API. Each operation that results in failure of any operation will now log the exception as well as report a timestamp and full stack trace in the results returned by the service API calls. Change-Id: I7336b28354e7740ea7d048bdf355e3c1a1b4436c --- swiftclient/utils.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'swiftclient/utils.py') diff --git a/swiftclient/utils.py b/swiftclient/utils.py index 8edfcfa..6ff6259 100644 --- a/swiftclient/utils.py +++ b/swiftclient/utils.py @@ -17,9 +17,9 @@ import hashlib import hmac import json import logging -import time - import six +import time +import traceback TRUE_VALUES = set(('true', '1', 'yes', 'on', 't', 'y')) EMPTY_ETAG = 'd41d8cd98f00b204e9800998ecf8427e' @@ -119,6 +119,20 @@ def parse_api_response(headers, body): return json.loads(body.decode(charset)) +def report_traceback(): + """ + Reports a timestamp and full traceback for a given exception. + + :return: Full traceback and timestamp. + """ + try: + formatted_lines = traceback.format_exc() + now = time.time() + return formatted_lines, now + except AttributeError: + return None, None + + class NoopMD5(object): def __init__(self, *a, **kw): pass -- cgit v1.2.1