From 4e46f9807a74b97aaae8178c551258ca0bf97759 Mon Sep 17 00:00:00 2001 From: Kun Huang Date: Mon, 22 Jul 2013 00:02:56 +0800 Subject: use 'exc_info=True' instead of import traceback We need log traceback message sometime, but people who ignore 'exc_info' argument would import traceback for getting traceback message. This work is already done by 'exc_info' in logging module. For example: logger.error('msg', exc_info=True) # exc_info evaluate as true and log message from sys.exc_info() logger.debug('msg', exc_info=(type, value, traceback)) # exc_info evaluate as an exception tuple and log message from this tuple logger.exception('msg') # exception add exc_info=1 automatically Change-Id: I9e1caf05fcf06bb977597076ebe278b593d70bf4 --- keystone/common/logging.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/keystone/common/logging.py b/keystone/common/logging.py index 8c036f02..d221edb7 100644 --- a/keystone/common/logging.py +++ b/keystone/common/logging.py @@ -23,7 +23,6 @@ import logging import logging.config import logging.handlers import pprint -import traceback # A list of things we want to replicate from logging. @@ -78,8 +77,7 @@ def fail_gracefully(f): try: return f(*args, **kw) except Exception as e: - # tracebacks are kept in the debug log - logging.debug(traceback.format_exc(e)) + logging.debug(e, exc_info=True) # exception message is printed to all logs logging.critical(e) -- cgit