MCPcopy Create free account
hub / github.com/binkuolo/fastapi / write_access_log

Function write_access_log

api/endpoints/common.py:11–31  ·  view source on GitHub ↗

写入访问日志 :param user_id: 用户ID :param req: 请求头 :param note: 备注 :return:

(req: Request, user_id: int,  note: str = None)

Source from the content-addressed store, hash-verified

9
10
11async 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)

Callers 2

account_loginFunction · 0.90
scan_checkFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected