~matsubara/ubuntu/trusty/python-urllib3/bug-1412545

« back to all changes in this revision

Viewing changes to urllib3/__init__.py

  • Committer: Package Import Robot
  • Author(s): Barry Warsaw
  • Date: 2012-11-01 15:31:36 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20121101153136-w2fm02askveqxxkx
Tags: 1.5-0ubuntu1
* New upstream release.  Remaining changes:
  - 01_do-not-use-embedded-python-six.patch: refreshed
  - 02_require-cert-verification.patch: refreshed
  - 03-fix-appenginge.patch: removed

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 
11
11
__author__ = 'Andrey Petrov (andrey.petrov@shazow.net)'
12
12
__license__ = 'MIT'
13
 
__version__ = '1.3'
 
13
__version__ = '1.5'
14
14
 
15
15
 
16
16
from .connectionpool import (
28
28
 
29
29
# Set default logging handler to avoid "No handler found" warnings.
30
30
import logging
31
 
try:
 
31
try:  # Python 2.7+
32
32
    from logging import NullHandler
33
33
except ImportError:
34
34
    class NullHandler(logging.Handler):
37
37
 
38
38
logging.getLogger(__name__).addHandler(NullHandler())
39
39
 
 
40
def add_stderr_logger(level=logging.DEBUG):
 
41
    """
 
42
    Helper for quickly adding a StreamHandler to the logger. Useful for
 
43
    debugging.
 
44
 
 
45
    Returns the handler after adding it.
 
46
    """
 
47
    # This method needs to be in this __init__.py to get the __name__ correct
 
48
    # even if urllib3 is vendored within another package.
 
49
    logger = logging.getLogger(__name__)
 
50
    handler = logging.StreamHandler()
 
51
    handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
 
52
    logger.addHandler(handler)
 
53
    logger.setLevel(level)
 
54
    logger.debug('Added an stderr logging handler to logger: %s' % __name__)
 
55
    return handler
 
56
 
40
57
# ... Clean up.
41
 
del logging
42
58
del NullHandler