[PATCH] run_command: log error messages using higher log level when return code is non-zero

From: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> run_command logs stdout and stderr output using the "debug" level. In this patch, if returncode is non-zero, it logs stderr output using the "error" level. It's helpful for diagnosing underlying command errors. Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> --- src/kimchi/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py index d4ab1a1..e89a93f 100644 --- a/src/kimchi/utils.py +++ b/src/kimchi/utils.py @@ -169,8 +169,13 @@ def run_command(cmd, timeout=None): out, error = proc.communicate() kimchi_log.debug("Run command: '%s'", " ".join(cmd)) - if out or error: - kimchi_log.debug("out:\n %s\nerror:\n %s", out, error) + if out: + kimchi_log.debug("out:\n%s", out) + + if proc.returncode != 0: + kimchi_log.error("rc: %s\nerror:\n%s", proc.returncode, error) + elif error: + kimchi_log.debug("error:\n%s", error) if timeout_flag[0]: msg = ("subprocess is killed by signal.SIGKILL for " -- 1.8.5.3

Reviewed-by: Daniel Barboza <danielhb@linux.vnet.ibm.com> On 02/26/2014 01:02 AM, zhshzhou@linux.vnet.ibm.com wrote:
From: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
run_command logs stdout and stderr output using the "debug" level. In this patch, if returncode is non-zero, it logs stderr output using the "error" level. It's helpful for diagnosing underlying command errors.
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> --- src/kimchi/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py index d4ab1a1..e89a93f 100644 --- a/src/kimchi/utils.py +++ b/src/kimchi/utils.py @@ -169,8 +169,13 @@ def run_command(cmd, timeout=None): out, error = proc.communicate() kimchi_log.debug("Run command: '%s'", " ".join(cmd))
- if out or error: - kimchi_log.debug("out:\n %s\nerror:\n %s", out, error) + if out: + kimchi_log.debug("out:\n%s", out) + + if proc.returncode != 0: + kimchi_log.error("rc: %s\nerror:\n%s", proc.returncode, error) + elif error: + kimchi_log.debug("error:\n%s", error)
if timeout_flag[0]: msg = ("subprocess is killed by signal.SIGKILL for "

Reviewed-by: Shu Ming <shuming@linux.vnet.ibm.com> 2014/2/26 12:02, zhshzhou@linux.vnet.ibm.com:
From: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com>
run_command logs stdout and stderr output using the "debug" level. In this patch, if returncode is non-zero, it logs stderr output using the "error" level. It's helpful for diagnosing underlying command errors.
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> --- src/kimchi/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py index d4ab1a1..e89a93f 100644 --- a/src/kimchi/utils.py +++ b/src/kimchi/utils.py @@ -169,8 +169,13 @@ def run_command(cmd, timeout=None): out, error = proc.communicate() kimchi_log.debug("Run command: '%s'", " ".join(cmd))
- if out or error: - kimchi_log.debug("out:\n %s\nerror:\n %s", out, error) + if out: + kimchi_log.debug("out:\n%s", out) + + if proc.returncode != 0: + kimchi_log.error("rc: %s\nerror:\n%s", proc.returncode, error) + elif error: + kimchi_log.debug("error:\n%s", error)
if timeout_flag[0]: msg = ("subprocess is killed by signal.SIGKILL for "

Reviewed-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> On 02/26/2014 12:02 PM, zhshzhou@linux.vnet.ibm.com wrote:
+ if out: + kimchi_log.debug("out:\n%s", out) + + if proc.returncode != 0: + kimchi_log.error("rc: %s\nerror:\n%s", proc.returncode, error) + elif error: + kimchi_log.debug("error:\n%s", error)
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

Applied. Thanks. Regards, Aline Manera
participants (5)
-
Aline Manera
-
Daniel H Barboza
-
Sheldon
-
Shu Ming
-
zhshzhou@linux.vnet.ibm.com