Writes a completed HTTP request to the logs. By default writes to the python root logger. To change this behavior either subclass Application and override this method, or pass a function in the application settings dictionary as ``log_function``.
(self, handler: RequestHandler)
| 2419 | raise KeyError("%s not found in named urls" % name) |
| 2420 | |
| 2421 | def log_request(self, handler: RequestHandler) -> None: |
| 2422 | """Writes a completed HTTP request to the logs. |
| 2423 | |
| 2424 | By default writes to the python root logger. To change |
| 2425 | this behavior either subclass Application and override this method, |
| 2426 | or pass a function in the application settings dictionary as |
| 2427 | ``log_function``. |
| 2428 | """ |
| 2429 | if "log_function" in self.settings: |
| 2430 | self.settings["log_function"](handler) |
| 2431 | return |
| 2432 | if handler.get_status() < 400: |
| 2433 | log_method = access_log.info |
| 2434 | elif handler.get_status() < 500: |
| 2435 | log_method = access_log.warning |
| 2436 | else: |
| 2437 | log_method = access_log.error |
| 2438 | request_time = 1000.0 * handler.request.request_time() |
| 2439 | log_method( |
| 2440 | "%d %s %.2fms", |
| 2441 | handler.get_status(), |
| 2442 | handler._request_summary(), |
| 2443 | request_time, |
| 2444 | ) |
| 2445 | |
| 2446 | |
| 2447 | class _HandlerDelegate(httputil.HTTPMessageDelegate): |
no test coverage detected