summaryrefslogtreecommitdiffstats
path: root/keystone/common
diff options
context:
space:
mode:
authorDolph Mathews <dolph.mathews@gmail.com>2012-03-05 16:47:58 -0600
committerDolph Mathews <dolph.mathews@gmail.com>2012-03-06 11:06:04 -0600
commitfd4e9616ddca4dbd0c4f0545c376167b966eae8d (patch)
tree04bead4be42f5f414173f0bb3814d095a1908161 /keystone/common
parenta18b3f29c4a977977e6bf29d1edcba43d5e6005b (diff)
Isolating backtraces to DEBUG (bug 947060)
Debug mode on: http://pastie.org/3529520 (full backtrace to stdout) Debug mode off: http://pastie.org/3529526 (Just an error message to stdout) Change-Id: I1d4e17cf73e7777c3cbaef7c5d7fd18a4f6e53dc
Diffstat (limited to 'keystone/common')
-rw-r--r--keystone/common/logging.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/keystone/common/logging.py b/keystone/common/logging.py
index 0d3f4693..77d6a8e1 100644
--- a/keystone/common/logging.py
+++ b/keystone/common/logging.py
@@ -8,6 +8,7 @@ import functools
import logging
import logging.config
import pprint
+import traceback
from logging.handlers import SysLogHandler
from logging.handlers import WatchedFileHandler
@@ -55,3 +56,20 @@ def log_debug(f):
logging.debug('')
return rv
return wrapper
+
+
+def fail_gracefully(f):
+ """Logs exceptions and aborts."""
+ @functools.wraps(f)
+ def wrapper(*args, **kw):
+ try:
+ return f(*args, **kw)
+ except Exception as e:
+ # tracebacks are kept in the debug log
+ logging.debug(traceback.format_exc(e))
+
+ # exception message is printed to all logs
+ logging.critical(e)
+
+ exit(1)
+ return wrapper