(self, code: int | str = "-", size: int | str = "-")
| 439 | _control_char_table[ord("\\")] = r"\\" |
| 440 | |
| 441 | def log_request(self, code: int | str = "-", size: int | str = "-") -> None: |
| 442 | try: |
| 443 | path = uri_to_iri(self.path) |
| 444 | msg = f"{self.command} {path} {self.request_version}" |
| 445 | except AttributeError: |
| 446 | # path isn't set if the requestline was bad |
| 447 | msg = self.requestline |
| 448 | |
| 449 | # Escape control characters that may be in the decoded path. |
| 450 | msg = msg.translate(self._control_char_table) |
| 451 | code = str(code) |
| 452 | |
| 453 | if code[0] == "1": # 1xx - Informational |
| 454 | msg = _ansi_style(msg, "bold") |
| 455 | elif code == "200": # 2xx - Success |
| 456 | pass |
| 457 | elif code == "304": # 304 - Resource Not Modified |
| 458 | msg = _ansi_style(msg, "cyan") |
| 459 | elif code[0] == "3": # 3xx - Redirection |
| 460 | msg = _ansi_style(msg, "green") |
| 461 | elif code == "404": # 404 - Resource Not Found |
| 462 | msg = _ansi_style(msg, "yellow") |
| 463 | elif code[0] == "4": # 4xx - Client Error |
| 464 | msg = _ansi_style(msg, "bold", "red") |
| 465 | else: # 5xx, or any other response |
| 466 | msg = _ansi_style(msg, "bold", "magenta") |
| 467 | |
| 468 | self.log("info", '"%s" %s %s', msg, code, size) |
| 469 | |
| 470 | def log_error(self, format: str, *args: t.Any) -> None: |
| 471 | self.log("error", format, *args) |
nothing calls this directly
no test coverage detected