From 1be26027e7b42cd65937ca185a106ce9139ba4c1 Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Mon, 26 Jun 2017 07:28:45 +0100 Subject: Improve logging of executed processes Improve readability of logged messages by separating the prefix from the message with new line and raise CalledProcessError if the exit code is non-zero. --- src/virtBootstrap/sources.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/virtBootstrap/sources.py') diff --git a/src/virtBootstrap/sources.py b/src/virtBootstrap/sources.py index 0ce2134..ca74313 100644 --- a/src/virtBootstrap/sources.py +++ b/src/virtBootstrap/sources.py @@ -60,17 +60,19 @@ def execute(cmd): """ Execute command and log debug message. """ + cmd_str = ' '.join(cmd) + logging.debug("Call command:\n%s", cmd_str) + proc = Popen(cmd, stdout=PIPE, stderr=PIPE) output, err = proc.communicate() - logging.debug("Command: %s", ' '.join(cmd)) + if output: - logging.debug("Stdout: %s", output) + logging.debug("Stdout:\n%s", output) if err: - logging.debug("Stderr: %s", err) + logging.debug("Stderr:\n%s", err) if proc.returncode != 0: - logging.error(_('Exit with non-zero code. %s'), proc.returncode) - raise CalledProcessError + raise CalledProcessError(proc.returncode, cmd_str) def safe_untar(src, dest): -- cgit