diff options
author | Radostin Stoyanov <rstoyanov1@gmail.com> | 2017-06-26 07:28:45 +0100 |
---|---|---|
committer | Cédric Bosdonnat <cbosdonnat@suse.com> | 2017-06-28 10:36:47 +0200 |
commit | 1be26027e7b42cd65937ca185a106ce9139ba4c1 (patch) | |
tree | 5412f41f6c8508ea45823716cbeaf1e42a550fb6 | |
parent | 15511df340154bb48197bfd903ee9ff4321588e9 (diff) | |
download | virt-bootstrap.git-1be26027e7b42cd65937ca185a106ce9139ba4c1.tar.gz virt-bootstrap.git-1be26027e7b42cd65937ca185a106ce9139ba4c1.tar.xz virt-bootstrap.git-1be26027e7b42cd65937ca185a106ce9139ba4c1.zip |
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.
-rw-r--r-- | src/virtBootstrap/sources.py | 12 |
1 files changed, 7 insertions, 5 deletions
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): |