Skip to content

Commit

Permalink
optimise log record access
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 committed Nov 7, 2024
1 parent d1a805b commit 8157bba
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions api/util/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,22 @@ def format(self, record: logging.LogRecord) -> str:
class GunicornAccessLogJsonFormatter(JsonFormatter):
def get_json_record(self, record: logging.LogRecord) -> dict[str, Any]:
response_time = datetime.strptime(record.args["t"], "[%d/%b/%Y:%H:%M:%S %z]")
url = record.args["U"]
if record.args["q"]:
url += f"?{record.args['q']}"
args = record.args
url = args["U"]
if q := args["q"]:
url += f"?{q}"

Check warning on line 42 in api/util/logging.py

View check run for this annotation

Codecov / codecov/patch

api/util/logging.py#L39-L42

Added lines #L39 - L42 were not covered by tests

return {
**super().get_json_record(record),
"time": response_time.isoformat(),
"path": url,
"remote_ip": record.args["h"],
"method": record.args["m"],
"status": str(record.args["s"]),
"user_agent": record.args["a"],
"referer": record.args["f"],
"duration_in_ms": record.args["M"],
"pid": record.args["p"],
"remote_ip": args["h"],
"method": args["m"],
"status": str(args["s"]),
"user_agent": args["a"],
"referer": args["f"],
"duration_in_ms": args["M"],
"pid": args["p"],
}


Expand Down

0 comments on commit 8157bba

Please sign in to comment.