Issue #46 invalid

Logging messages not being formatted

Brett Cannon
created an issue

E.g. [ERROR] Failed to get external data for %s: %s

Comments (7)

  1. Vinay Sajip

    I can't reproduce this with the latest distlib - which version are you using, and which version of Python, on which OS? Can you show a more complete traceback? The relevant exception clause is here:

    except Exception as e:
            logger.exception('Failed to get external data for %s: %s', url, e)
    

    and I can't quite see what's wrong with it.

  2. Brett Cannon reporter

    Python 3.4 with the latest release version on OS X. And there is no traceback. The output from the logs is literally [ERROR] Failed to get external data for %s: %s, i.e. the string interpolation is occurring.

  3. Vinay Sajip

    Unfortunately, I have no access to Python 3.4 on OS X. With Python 3.3 on OS X 10.5, the logging works as expected and a traceback is produced. I can't see (from code inspection) what the problem might be.

  4. Brett Cannon reporter
    > ./py34_venv/bin/python -m unittest caniusepython3.test.test_dependencies
    .....[ERROR] Failed to get external data for %s: %s
    Traceback (most recent call last):
      File "/Users/bcannon/Repositories/caniusepython3/py34_venv/lib/python3.4/site-packages/distlib/util.py", line 744, in _get_external_data
        resp = urlopen(url)
      File "/Users/bcannon/Repositories/cpython/py3.4/Lib/urllib/request.py", line 153, in urlopen
        return opener.open(url, data, timeout)
      File "/Users/bcannon/Repositories/cpython/py3.4/Lib/urllib/request.py", line 461, in open
        response = meth(req, response)
      File "/Users/bcannon/Repositories/cpython/py3.4/Lib/urllib/request.py", line 574, in http_response
        'http', request, response, code, msg, hdrs)
      File "/Users/bcannon/Repositories/cpython/py3.4/Lib/urllib/request.py", line 499, in error
        return self._call_chain(*args)
      File "/Users/bcannon/Repositories/cpython/py3.4/Lib/urllib/request.py", line 433, in _call_chain
        result = func(*args)
      File "/Users/bcannon/Repositories/cpython/py3.4/Lib/urllib/request.py", line 582, in http_error_default
        raise HTTPError(req.full_url, code, msg, hdrs, fp)
    urllib.error.HTTPError: HTTP Error 404: Not Found
    /Users/bcannon/Repositories/caniusepython3/caniusepython3/dependencies.py:58: DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
      log.warn('{0} not found'.format(project_name))
    [WARNING] sdflksjdfsadfsadfad not found
    
  5. Vinay Sajip

    This is a bug in caniusepython3. The line which reads

    logging.basicConfig(format='[%(levelname)s] %(msg)s')
    

    should read

    logging.basicConfig(format='[%(levelname)s] %(message)s')
    

    The former uses the unformatted message in the logging record (preserved because applying the formatting is done lazily).

    I noticed an anti-pattern in caniusepython/__init__py: you are calling basicConfig() (which adds handlers to the root logger) on module import, where the logging documentation explicitly recommends against doing this. In general, basicConfig() or other configuration APIs should only be called from an if __name__ == '__main__' clause.

  6. Log in to comment