comparison mercurial/httpconnection.py @ 14375:436e5379d7ba

httpconnection: improved logging formatting I had to use this debugging output for the first time recently when looking for a problem, and the lack of good formatting made things difficult.
author Augie Fackler <durin42@gmail.com>
date Mon, 16 May 2011 16:59:45 -0500
parents bf85c2639700
children c864f5e743ef
comparison
equal deleted inserted replaced
14374:51f444e85734 14375:436e5379d7ba
105 httpclient.HTTPConnection.request(self, method, uri, body=body, 105 httpclient.HTTPConnection.request(self, method, uri, body=body,
106 headers=headers) 106 headers=headers)
107 107
108 108
109 _configuredlogging = False 109 _configuredlogging = False
110 LOGFMT = '%(levelname)s:%(name)s:%(lineno)d:%(message)s'
110 # Subclass BOTH of these because otherwise urllib2 "helpfully" 111 # Subclass BOTH of these because otherwise urllib2 "helpfully"
111 # reinserts them since it notices we don't include any subclasses of 112 # reinserts them since it notices we don't include any subclasses of
112 # them. 113 # them.
113 class http2handler(urllib2.HTTPHandler, urllib2.HTTPSHandler): 114 class http2handler(urllib2.HTTPHandler, urllib2.HTTPSHandler):
114 def __init__(self, ui, pwmgr): 115 def __init__(self, ui, pwmgr):
120 loglevel = ui.config('ui', 'http2debuglevel', default=None) 121 loglevel = ui.config('ui', 'http2debuglevel', default=None)
121 if loglevel and not _configuredlogging: 122 if loglevel and not _configuredlogging:
122 _configuredlogging = True 123 _configuredlogging = True
123 logger = logging.getLogger('mercurial.httpclient') 124 logger = logging.getLogger('mercurial.httpclient')
124 logger.setLevel(getattr(logging, loglevel.upper())) 125 logger.setLevel(getattr(logging, loglevel.upper()))
125 logger.addHandler(logging.StreamHandler()) 126 handler = logging.StreamHandler()
127 handler.setFormatter(logging.Formatter(LOGFMT))
128 logger.addHandler(handler)
126 129
127 def close_all(self): 130 def close_all(self):
128 """Close and remove all connection objects being kept for reuse.""" 131 """Close and remove all connection objects being kept for reuse."""
129 for openconns in self._connections.values(): 132 for openconns in self._connections.values():
130 for conn in openconns: 133 for conn in openconns: