[QUESTION] fastapi uvicorn access filtered when sending to file
fmieres opened this issue · 3 comments
I set up a file handler and im getting all logs ok except for the access ones. they are only sent to stdout
{
...
"type": "request",
...
}
If i remove json-logging set up, i get those access requests logged into the file. Is something stopping them from propagating ?
Im sorry if this is not the place for the question. Any suggestion will be appretiated
Thanks for answering so fast!!! :D
Ive manually enabled it and also started logging to file fastapi-request-logger . Now i get request logged into a file but they are not as fancy as the one you provide . Example :
to file :
{"written_at": "2021-07-08T15:54:22.635Z", "written_ts": 1625759662635810000, "msg": "172.25.0.1:36448 - \"GET /api/v1/user/get_user_data HTTP/1.1\" 200", "type": "log", "logger": "uvicorn.access", "thread": "MainThread", "level": "INFO", "module": "h11_impl", "line_no": 451, "correlation_id": "-"}
to console:
{"written_at": "2021-07-08T15:54:22.633Z", "written_ts": 1625759662633872000, "type": "request", "correlation_id": "c351cb20-e004-11eb-b0de-0242ac190004", "remote_user": "-", "request": "/api/v1/user/get_user_data", "referer": "-", "x_forwarded_for": "-", "protocol": "HTTP/1.1", "method": "GET", "remote_ip": "x.x.x.x", "request_size_b": -1, "remote_host": "x.x.x.x, "remote_port": 36448, "request_received_at": "2021-07-08T15:54:21.976Z", "response_time_ms": 657, "response_status": 200, "response_size_b": "186", "response_content_type": "application/json", "response_sent_at": "2021-07-08T15:54:22.633Z"}
I know it may be a long shot, but any suggestion as to why im not getting the latter to file ? which logger is producing them ?
Thanks in advance.
u need to use the formatter provided by json_logging library. u can manually set it by doing something like this. U can either use JSONLogWebFormatter (provide correlation id) or JSONLogFormatter