'Redirect :class:`sys.stdout` and :class:`sys.stderr` to logger.
Arguments:
logger (logging.Logger): Logger instance to redirect to.
loglevel (int, str): The loglevel redirected message
will be logged as.'

def redirect_stdouts_to_logger(self, logger, loglevel=None, stdout=True, stderr=True):

    proxy = LoggingProxy(logger, loglevel)
    if stdout:
        sys.stdout = proxy
    if stderr:
        sys.stderr = proxy
    return proxy
