Skip to content
Permalink
Browse files

scripts: tweak runner-related command output

Having common log handlers now lets us improve our logging output so
that info messages are prefixed with the runner they came from, and
doing something similar with the high level steps as we go, like this:

   -- west <command>: using runners
   -- runners.RUNNER_NAME: doing something
   <output from RUNNER_NAME subprocesses go here>
   -- runners.RUNNER_NAME: all done, bye

We can also colorize the west output to make it stand out better from
subprocesses, using the same output formatting style that west
commands like west list do.

Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
  • Loading branch information...
mbolivar authored and carlescufi committed Jun 3, 2019
1 parent ddce583 commit ec8dbf34dc4259f0b8bb114972057f40346723c6
Showing with 6 additions and 3 deletions.
  1. +6 −3 scripts/west_commands/run_common.py
@@ -36,11 +36,13 @@
else:
LOG_LEVEL = logging.INFO

def _banner(msg):
log.inf('-- ' + msg, colorize=True)

class WestLogFormatter(logging.Formatter):

def __init__(self):
super().__init__(fmt='%(message)s')
super().__init__(fmt='%(name)s: %(message)s')

class WestLogHandler(logging.Handler):

@@ -59,7 +61,7 @@ def emit(self, record):
elif lvl >= logging.WARNING:
log.wrn(fmt)
elif lvl >= logging.INFO:
log.inf(fmt)
_banner(fmt)
elif lvl >= logging.DEBUG:
log.dbg(fmt)
else:
@@ -192,6 +194,7 @@ def do_run_common(command, args, runner_args, cached_runner_var):
build_dir = _build_dir(args)

if not args.skip_rebuild:
_banner('west {}: rebuilding'.format(command_name))
try:
cmake.run_build(build_dir)
except CalledProcessError:
@@ -226,7 +229,7 @@ def do_run_common(command, args, runner_args, cached_runner_var):
manually, or check your board's documentation for
alternative instructions.""".format(command_name, board)))

log.inf('Using runner:', runner)
_banner('west {}: using runner {}'.format(command_name, runner))
if runner not in available:
log.wrn('Runner {} is not configured for use with {}, '
'this may not work'.format(runner, board))

0 comments on commit ec8dbf3

Please sign in to comment.
You can’t perform that action at this time.