From db96876599f28469adea452a9f18e536956bacba Mon Sep 17 00:00:00 2001 From: Luis Toledo Date: Wed, 9 Nov 2022 09:35:08 -0300 Subject: [PATCH] fix log output --- contents/container-inspect | 15 ++++++++++----- contents/container-stats | 14 ++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/contents/container-inspect b/contents/container-inspect index 7dc5e79..a3ce6dd 100644 --- a/contents/container-inspect +++ b/contents/container-inspect @@ -52,13 +52,18 @@ p = Popen( stdout=PIPE, stderr=STDOUT ) + exitcode = p.wait() -if log_level == 'DEBUG': - log.debug("Command execution stdout: '%s' ..." % p.stdout.read()) - log.debug("Command execution stderr: '%s' ..." % p.stderr.read()) -else: - print(p.stdout.read()) +# Print lines to stdout while waiting for command to finish +while True: + line = p.stdout.readline().rstrip() + if line: + print(line.decode()) + if p.poll() is not None: + break + +exitcode = p.poll() if exitcode != 0: log.error('Command execution failed with exit code: %s' % str(exitcode)) diff --git a/contents/container-stats b/contents/container-stats index b3fedcb..1e5712e 100644 --- a/contents/container-stats +++ b/contents/container-stats @@ -52,13 +52,15 @@ p = Popen( stdout=PIPE, stderr=STDOUT ) -exitcode = p.wait() +# Print lines to stdout while waiting for command to finish +while True: + line = p.stdout.readline().rstrip() + if line: + print(line.decode()) + if p.poll() is not None: + break -if log_level == 'DEBUG': - log.debug("Command execution stdout: '%s' ..." % p.stdout.read()) - log.debug("Command execution stderr: '%s' ..." % p.stderr.read()) -else: - print(p.stdout.read()) +exitcode = p.poll() if exitcode != 0: log.error('Command execution failed with exit code: %s' % str(exitcode))