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)
| 2251 | raise KeyError("%s not found in named urls" % name) |
| 2252 | |
| 2253 | def log_request(self, handler: RequestHandler) -> None: |
| 2254 | """Writes a completed HTTP request to the logs. |
| 2255 | |
| 2256 | By default writes to the python root logger. To change |
| 2257 | this behavior either subclass Application and override this method, |
| 2258 | or pass a function in the application settings dictionary as |
| 2259 | ``log_function``. |
| 2260 | """ |
| 2261 | if "log_function" in self.settings: |
| 2262 | self.settings["log_function"](handler) |
| 2263 | return |
| 2264 | if handler.get_status() < 400: |
| 2265 | log_method = access_log.info |
| 2266 | elif handler.get_status() < 500: |
| 2267 | log_method = access_log.warning |
| 2268 | else: |
| 2269 | log_method = access_log.error |
| 2270 | request_time = 1000.0 * handler.request.request_time() |
| 2271 | log_method( |
| 2272 | "%d %s %.2fms", |
| 2273 | handler.get_status(), |
| 2274 | handler._request_summary(), |
| 2275 | request_time, |
| 2276 | ) |
| 2277 | |
| 2278 | |
| 2279 | class _HandlerDelegate(httputil.HTTPMessageDelegate): |
no test coverage detected