写入访问日志 :param user_id: 用户ID :param req: 请求头 :param note: 备注 :return:
(req: Request, user_id: int, note: str = None)
| 9 | |
| 10 | |
| 11 | async def write_access_log(req: Request, user_id: int, note: str = None): |
| 12 | """ |
| 13 | 写入访问日志 |
| 14 | :param user_id: 用户ID |
| 15 | :param req: 请求头 |
| 16 | :param note: 备注 |
| 17 | :return: |
| 18 | """ |
| 19 | data = { |
| 20 | "user_id": user_id, |
| 21 | "target_url": req.get("path"), |
| 22 | "user_agent": req.headers.get('user-agent'), |
| 23 | "request_params": { |
| 24 | "method": req.method, |
| 25 | "params": dict(req.query_params), |
| 26 | "body": bytes(await req.body()).decode() |
| 27 | }, |
| 28 | "ip": req.headers.get('x-forwarded-for'), |
| 29 | "note": note |
| 30 | } |
| 31 | await AccessLog.create(**data) |
no outgoing calls
no test coverage detected