Esempio n. 1
0
async def read_stdout(stdout, log_fh):
    """Log STDOUT from the task subprocess to the log filehandle.
    """
    while True:
        line = await stdout.readline()
        if line:
            log.debug(to_unicode(line.rstrip()))
            print(to_unicode(line), file=log_fh, end="")
        else:
            break
Esempio n. 2
0
async def read_stdout(stdout, log_fh):
    """Log STDOUT from the task subprocess to the log filehandle.
    """
    while True:
        line = await stdout.readline()
        if line:
            log.debug(to_unicode(line.rstrip()))
            print(to_unicode(line), file=log_fh, end="")
        else:
            break
Esempio n. 3
0
async def log_errors(reader, log_fh, error_fh):
    """Log STDERR from the task subprocess to both the log and error
    filehandles.
    """
    while True:
        line = await reader.readline()
        if not line:
            break
        line = to_unicode(line)
        log.debug('ERROR {}'.format(line.rstrip()))
        print('ERROR {}'.format(line), file=log_fh, end="")
        print(line, file=error_fh, end="")
Esempio n. 4
0
async def log_errors(reader, log_fh, error_fh):
    """Log STDERR from the task subprocess to both the log and error
    filehandles.
    """
    while True:
        line = await reader.readline()
        if not line:
            break
        line = to_unicode(line)
        log.debug('ERROR {}'.format(line.rstrip()))
        print('ERROR {}'.format(line), file=log_fh, end="")
        print(line, file=error_fh, end="")
Esempio n. 5
0
async def pipe_to_log(pipe, filehandles=(), level=logging.INFO):
    """Log from a subprocess PIPE.

    Args:
        pipe (filehandle): subprocess process STDOUT or STDERR
        filehandles (list of filehandles, optional): the filehandle(s) to write
            to.  If empty, don't write to a separate file.  Defaults to ().
        level (int, optional): the level to log to.  Defaults to `logging.INFO`.
    """
    while True:
        line = await pipe.readline()
        if line:
            line = to_unicode(line)
            log.log(level, line.rstrip())
            for filehandle in filehandles:
                print(line, file=filehandle, end="")
        else:
            break
Esempio n. 6
0
async def pipe_to_log(pipe: StreamReader,
                      filehandles: Sequence[IO[str]] = (),
                      level: int = logging.INFO) -> None:
    """Log from a subprocess PIPE.

    Args:
        pipe (filehandle): subprocess process STDOUT or STDERR
        filehandles (list of filehandles, optional): the filehandle(s) to write
            to.  If empty, don't write to a separate file.  Defaults to ().
        level (int, optional): the level to log to.  Defaults to ``logging.INFO``.

    """
    while True:
        line = await pipe.readline()  # type: Union[str, bytes]
        if line:
            line = to_unicode(line)
            log.log(level, line.rstrip())
            for filehandle in filehandles:
                print(line, file=filehandle, end="")
        else:
            break
Esempio n. 7
0
def test_nontext_to_unicode(non_text):
    assert non_text == utils.to_unicode(non_text)
Esempio n. 8
0
def test_text_to_unicode(text):
    assert text == utils.to_unicode(text)
    assert text == utils.to_unicode(text.encode("utf-8"))
Esempio n. 9
0
 def test_nontext_to_unicode(self, non_text):
     assert non_text == utils.to_unicode(non_text)
Esempio n. 10
0
 def test_text_to_unicode(self, text):
     assert text == utils.to_unicode(text)
     assert text == utils.to_unicode(text.encode('utf-8'))
Esempio n. 11
0
 def test_text_to_unicode(self, text):
     assert text == utils.to_unicode(text)
     assert text == utils.to_unicode(text.encode('utf-8'))