[Kimchi-devel] [PATCH] Add the command to run_command error and debug logging

Zhou Zheng Sheng zhshzhou at linux.vnet.ibm.com
Wed Apr 2 08:42:39 UTC 2014


on 2014/04/02 03:53, Aline Manera wrote:
> 
> Reviewed-by: Aline Manera <alinefm at linux.vnet.ibm.com>
> 
> On 04/01/2014 02:37 PM, Christy Perez wrote:
>> I was debugging an issue and seeing rc's but not completely
>> sure which command they were caused by. I think it's just nice
>> to include what generated an rc, and also have all the output
>> on the same line to remove any uncertainty.
>>
>> For example, instead of:
>>
>> rc: -15
>> error:
>>
>> rc: -15
>> error:
>>
>> You'll see:
>> rc: -15  error:  returned from cmd: /usr/bin/example-command-here
>>
>> Signed-off-by: Christy Perez <christy at linux.vnet.ibm.com>
>> ---
>>   src/kimchi/utils.py | 6 ++++--
>>   1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/kimchi/utils.py b/src/kimchi/utils.py
>> index 6c29e0e..11a36a4 100644
>> --- a/src/kimchi/utils.py
>> +++ b/src/kimchi/utils.py
>> @@ -174,9 +174,11 @@ def run_command(cmd, timeout=None):
>>               kimchi_log.debug("out:\n%s", out)
>>
>>           if proc.returncode != 0:
>> -            kimchi_log.error("rc: %s\nerror:\n%s", proc.returncode,
>> error)
>> +            kimchi_log.error("rc: %s error: %s returned from
>> cmd:".join(cmd),
>> +                             proc.returncode, error)
>>           elif error:
>> -            kimchi_log.debug("error:\n%s", error)
>> +            kimchi_log.debug("error: %s returned from cmd: ".join(cmd),
>> +                              error, cmd)

Since the error output can be long and can contain '\n', I think the cmd
should be in the front of the log message. For example,

kimchi_log.error("cmd: %s\nrc: %s\nerror:\n%s",
               " ".join(cmd), proc.returncode, error)

Moreover,
  "error: %s returned from cmd: ".join(cmd)
does not look correct. When we call "aStr.join(sequence)", aStr serves
as a delimiter. For example,

>>> "|||".join(['1', '2', '3'])
'1|||2|||3'

If we just want to paste cmd to the end of the message. We can just
 debug("error: %s returned from cmd: %s", error, ' '.joinc(cmd))

>>
>>           if timeout_flag[0]:
>>               msg = ("subprocess is killed by signal.SIGKILL for "
> 
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
> 


-- 
Thanks and best regards!

Zhou Zheng Sheng / 周征晟
E-mail: zhshzhou at linux.vnet.ibm.com
Telephone: 86-10-82454397




More information about the Kimchi-devel mailing list