提交 5ee2b5c6 编写于 作者: L Lukáš Doktor 提交者: Cleber Rosa

scripts.avocado: Simplify error streams detection

Avoid unnecessary complexity of quering for enabled logs and only support
os.environ to show the full traceback.

Additionally avoid problems with redirected sys.stderr by writing
directly to fd 2, which is STDERR.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 83a50b5f
......@@ -16,7 +16,6 @@
import sys
try:
import logging
import os
import tempfile
import traceback
......@@ -29,11 +28,10 @@ except:
def handle_exception(*exc_info):
# Print traceback into avocado.app.traceback if initialized
# Print traceback if AVOCADO_LOG_DEBUG environment variable is set
msg = "Avocado crashed:\n" + "".join(traceback.format_exception(*exc_info))
log = logging.getLogger("avocado.app.tracebacks")
if getattr(log, "handlers", False):
log.error(msg)
if os.environ.get("AVOCADO_LOG_DEBUG"):
os.write(2, msg + '\n')
# Store traceback in data_dir or TMPDIR
crash_dir = None
prefix = "avocado-traceback-"
......@@ -52,17 +50,7 @@ def handle_exception(*exc_info):
# Print friendly message in console-like output
msg = ("Avocado crashed unexpectedly: %s\nYou can find details in %s"
% (exc_info[1], name))
for name in ("avocado.app", "avocado.test", None):
log = logging.getLogger(name)
for handler in getattr(log, "handlers", []):
if isinstance(handler, logging.StreamHandler):
break
else:
continue
log.critical(msg)
break
else: # Log not found, use stderr and hope it's enabled
sys.stderr.write(msg + '\n')
os.write(2, msg + '\n')
# This exit code is replicated from avocado/core/exit_codes.py and not
# imported because we are dealing with import failures
sys.exit(-1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册