'Emit log messages if we\'re running out of ratelimit.'

def log_ratelimit_headers(self, limit, remaining, reset):

    if (None in (limit, remaining, reset)):
        return
    percent_remaining = (remaining / limit)
    if (percent_remaining < 0.5):
        log_msg = u'{0}    API:    {1:.1%}    of    ratelimit    has    been    consumed,    {2}    requests    remaining,    resets    {3}.'.format(self.name, (1 - percent_remaining), remaining, to_age(reset))
        log_lvl = logging.WARNING
        if (percent_remaining < 0.2):
            log_lvl = logging.ERROR
        elif (percent_remaining < 0.05):
            log_lvl = logging.CRITICAL
        log(log_msg, log_lvl)
