mirror of
https://github.com/ceph/ceph
synced 2025-02-16 07:17:21 +00:00
ceph-daemon: do not screw up line splitting
When we log stdout and stderr, we were artificially adding line splits due to reading 1024 bytes at a time and assuming it was aligned with a newline. Fix by keeping partial lines buffered and only log them once they are complete (or the call finishes). Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
parent
e38eeb62c5
commit
83b072f3cc
@ -115,6 +115,8 @@ def call(command, desc=None, verbose=False, **kwargs):
|
||||
err = ''
|
||||
reads = None
|
||||
stop = False
|
||||
out_buffer = '' # partial line (no newline yet)
|
||||
err_buffer = '' # partial line (no newline yet)
|
||||
while not stop:
|
||||
if reads and process.poll() is not None:
|
||||
# we want to stop, but first read off anything remaining
|
||||
@ -132,14 +134,20 @@ def call(command, desc=None, verbose=False, **kwargs):
|
||||
message = message.decode('utf-8')
|
||||
if fd == process.stdout.fileno():
|
||||
out += message
|
||||
for line in message.splitlines():
|
||||
message = out_buffer + message
|
||||
lines = message.split('\n')
|
||||
out_buffer = lines.pop()
|
||||
for line in lines:
|
||||
if verbose:
|
||||
logger.info(desc + ':stdout ' + line)
|
||||
else:
|
||||
logger.debug(desc + ':stdout ' + line)
|
||||
elif fd == process.stderr.fileno():
|
||||
err += message
|
||||
for line in message.splitlines():
|
||||
message = err_buffer + message
|
||||
lines = message.split('\n')
|
||||
err_buffer = lines.pop()
|
||||
for line in lines:
|
||||
if verbose:
|
||||
logger.info(desc + ':stderr ' + line)
|
||||
else:
|
||||
@ -151,6 +159,17 @@ def call(command, desc=None, verbose=False, **kwargs):
|
||||
|
||||
returncode = process.wait()
|
||||
|
||||
if out_buffer != '':
|
||||
if verbose:
|
||||
logger.info(desc + ':stdout ' + out_buffer)
|
||||
else:
|
||||
logger.debug(desc + ':stdout ' + out_buffer)
|
||||
if err_buffer != '':
|
||||
if verbose:
|
||||
logger.info(desc + ':stderr ' + err_buffer)
|
||||
else:
|
||||
logger.debug(desc + ':stderr ' + err_buffer)
|
||||
|
||||
if returncode != 0 and verbose_on_failure and not verbose:
|
||||
# dump stdout + stderr
|
||||
logger.info('Non-zero exit code %d from %s' % (returncode, ' '.join(command)))
|
||||
|
Loading…
Reference in New Issue
Block a user