'Get log for a specific try number.
:param ti: current task instance
:param log_filename: relative filename to fetch the log'

def _get_log(self, ti, log_filename):

    log = ''
    remote_log_base = conf.get('core', 'REMOTE_BASE_LOG_FOLDER')
    remote_log_loaded = False
    if remote_log_base:
        remote_log_path = os.path.join(remote_log_base, log_filename)
        remote_log = ''
        if remote_log_path.startswith('s3:/'):
            s3_log = log_utils.S3Log()
            if s3_log.log_exists(remote_log_path):
                remote_log += s3_log.read(remote_log_path, return_error=True)
                remote_log_loaded = True
        elif remote_log_path.startswith('gs:/'):
            gcs_log = log_utils.GCSLog()
            if gcs_log.log_exists(remote_log_path):
                remote_log += gcs_log.read(remote_log_path, return_error=True)
                remote_log_loaded = True
        else:
            remote_log += '***    Unsupported    remote    log    location.'
        if remote_log:
            log += '***    Reading    remote    log    from    {}.\n{}\n'.format(remote_log_path, remote_log)
    if (not remote_log_loaded):
        local_log_base = os.path.expanduser(conf.get('core', 'BASE_LOG_FOLDER'))
        local_log_path = os.path.join(local_log_base, log_filename)
        if os.path.exists(local_log_path):
            try:
                f = open(local_log_path)
                log += ('***    Reading    local    log.\n' + ''.join(f.readlines()))
                f.close()
            except:
                log = '***    Failed    to    load    local    log    file:    {0}.\n'.format(local_log_path)
        else:
            WORKER_LOG_SERVER_PORT = conf.get('celery', 'WORKER_LOG_SERVER_PORT')
            url = os.path.join('http://{ti.hostname}:{WORKER_LOG_SERVER_PORT}/log', log_filename).format(**locals())
            log += "***    Log    file    isn't    local.\n"
            log += '***    Fetching    here:    {url}\n'.format(**locals())
            try:
                import requests
                timeout = None
                try:
                    timeout = conf.getint('webserver', 'log_fetch_timeout_sec')
                except (AirflowConfigException, ValueError):
                    pass
                response = requests.get(url, timeout=timeout)
                response.raise_for_status()
                log += ('\n' + response.text)
            except:
                log += '***    Failed    to    fetch    log    file    from    work    r.\n'.format(**locals())
    if (PY2 and (not isinstance(log, unicode))):
        log = log.decode('utf-8')
    return log
