1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-06-24 01:06:01 +01:00

fw: fix error logging

- Keep track of logged exceptions inside log_error itself.
- signal: log the exception, if there is one  in the finally clause of
  the  signal wrapper; this will ensure that the error will be logged
  closer to the command that originated.
- entrypoint: use log.log_error for top-level error logging, rather than
  the  entrypoint logger directly; this will ensure that errors are not
  repeated unnecessarily.
- Log CTRL-C message at zeroth indent level to make it easier to see in
  the  non-verbose output where it occurred.
This commit is contained in:
Sergei Trofimov
2018-02-28 15:18:58 +00:00
committed by Marc Bonnici
parent 6fe31d6cad
commit 04ab336afc
4 changed files with 24 additions and 15 deletions

@ -152,6 +152,13 @@ def dedent():
_indent_level -= 1
def set_indent_level(level):
global _indent_level
old_level = _indent_level
_indent_level = level
return old_level
def log_error(e, logger, critical=False):
"""
Log the specified Exception as an error. The Error message will be formatted
@ -163,13 +170,18 @@ def log_error(e, logger, critical=False):
level, otherwise it will be logged as ``logging.ERROR``.
"""
if getattr(e, 'logged', None):
return
if critical:
log_func = logger.critical
else:
log_func = logger.error
if isinstance(e, KeyboardInterrupt):
log_func('Got CTRL-C. Aborting.')
old_level = set_indent_level(0)
logger.info('Got CTRL-C. Aborting.')
set_indent_level(old_level)
elif isinstance(e, WAError) or isinstance(e, DevlibError):
log_func(str(e))
elif isinstance(e, subprocess.CalledProcessError):