MCPcopy
hub / github.com/benoitc/gunicorn / atoms

Method atoms

gunicorn/glogging.py:290–342  ·  view source on GitHub ↗

Gets atoms for log formatting.

(self, resp, req, environ, request_time)

Source from the content-addressed store, hash-verified

288 self.error_log.log(lvl, msg, *args, **kwargs)
289
290 def atoms(self, resp, req, environ, request_time):
291 """ Gets atoms for log formatting.
292 """
293 status = resp.status
294 if isinstance(status, str):
295 status = status.split(None, 1)[0]
296 atoms = {
297 'h': environ.get('REMOTE_ADDR', '-'),
298 'l': '-',
299 'u': self._get_user(environ) or '-',
300 't': self.now(),
301 'r': "%s %s %s" % (environ['REQUEST_METHOD'],
302 environ['RAW_URI'],
303 environ["SERVER_PROTOCOL"]),
304 's': status,
305 'm': environ.get('REQUEST_METHOD'),
306 'U': environ.get('PATH_INFO'),
307 'q': environ.get('QUERY_STRING'),
308 'H': environ.get('SERVER_PROTOCOL'),
309 'b': getattr(resp, 'sent', None) is not None and str(resp.sent) or '-',
310 'B': getattr(resp, 'sent', None),
311 'f': environ.get('HTTP_REFERER', '-'),
312 'a': environ.get('HTTP_USER_AGENT', '-'),
313 'T': request_time.seconds,
314 'D': (request_time.seconds * 1000000) + request_time.microseconds,
315 'M': (request_time.seconds * 1000) + int(request_time.microseconds / 1000),
316 'L': "%d.%06d" % (request_time.seconds, request_time.microseconds),
317 'p': "<%s>" % os.getpid()
318 }
319
320 # add request headers
321 if hasattr(req, 'headers'):
322 req_headers = req.headers
323 else:
324 req_headers = req
325
326 if hasattr(req_headers, "items"):
327 req_headers = req_headers.items()
328
329 atoms.update({"{%s}i" % k.lower(): v for k, v in req_headers})
330
331 resp_headers = resp.headers
332 if hasattr(resp_headers, "items"):
333 resp_headers = resp_headers.items()
334
335 # add response headers
336 atoms.update({"{%s}o" % k.lower(): v for k, v in resp_headers})
337
338 # add environ variables
339 environ_variables = environ.items()
340 atoms.update({"{%s}e" % k.lower(): v for k, v in environ_variables})
341
342 return atoms
343
344 @property
345 def access_log_enabled(self):

Calls 4

_get_userMethod · 0.95
nowMethod · 0.95
itemsMethod · 0.80
getMethod · 0.45