提交 155b7f87 编写于 作者: C Cleber Rosa

avocado.utils.datadrainer: introduce line logger

This drainer will wait for a complete new line, buffering incomplete
lines as needed.  When complete lines are found, it will log them via
a standard Python logging API.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 f166ce82
......@@ -165,3 +165,28 @@ class BufferFDDrainer(FDDrainer):
Returns the buffer data, as bytes
"""
return self._data.getvalue()
class LineLogger(FDDrainer):
name = 'avocado.utils.datadrainer.LineLogger'
def __init__(self, source, stop_check=None, name=None, logger=None):
super(LineLogger, self).__init__(source, stop_check, name)
self._logger = logger
self._buffer = io.BytesIO()
def write(self, data):
if b'\n' not in data:
self._buffer.write(data)
return
data = self._buffer.getvalue() + data
lines = data.split(b'\n')
if not lines[-1].endswith(b'\n'):
self._buffer.close()
self._buffer = io.BytesIO()
self._buffer.write(lines[-1])
for line in lines:
line = line.decode(errors='replace').rstrip('\n')
if line:
self._logger.debug(line)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册