summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--custodia/log.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/custodia/log.py b/custodia/log.py
index a04288d..ff71137 100644
--- a/custodia/log.py
+++ b/custodia/log.py
@@ -1,20 +1,27 @@
# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
-import io
import sys
import time
import traceback
+try:
+ from StringIO import StringIO
+except ImportError:
+ from io import StringIO
DEBUG = False
def stacktrace():
- with io.BytesIO() as f:
- _, _, tb = sys.exc_info()
+ _, _, tb = sys.exc_info()
+ if tb is None:
+ return None
+ try:
+ f = StringIO()
traceback.print_tb(tb, None, file=f)
- del tb
return f.getvalue()
+ finally:
+ del tb
def get_time():
@@ -32,7 +39,9 @@ def error(msg, head=None):
def debug(msg):
if DEBUG:
error(msg, 'DEBUG')
- sys.stderr.write(stacktrace())
+ trace = stacktrace()
+ if trace is not None:
+ sys.stderr.write(trace + '\n')
AUDIT_NONE = 0