Fastapi logging
See original GitHub issueHow can I log a request with his params and headers ?. Something like this:
INFO 2020-08-13 13:36:33.494 uvicorn.protocols.http.h11_impl:send - 127.0.0.1:52660 - "GET /url1/url2/ HTTP/1.1" 400 params= {"some": value, "some1":value} headers={"header1": value}
I’m using loguru with fastapi and uvicorn.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
FastAPI logging - Phil Girard
FastAPI logging. Here is how I setup my python logging for a fastAPI project. I have the following fastAPI file architecture: main.py logging.conf...
Read more >Logging & Tracing in Python, FastApi, OpenCensus and Azure
Learn how to correctly log & trace in Python, FastApi and then collect & visualize them. Tagged with python, fastapi, logging.
Read more >Adding python logging to FastApi endpoints, hosted on docker ...
I have a fastapi app on which I want to add python logging. I followed the basic tutorial and added this, however this...
Read more >Debugging - FastAPI
You can connect the debugger in your editor, for example with Visual Studio Code or PyCharm. Call uvicorn ¶. In your FastAPI application,...
Read more >fastapi-log - PyPI
Fastapi Route Log. License. A FastAPI router for logging every request. Installation. $ pip install fastapi_log. Dashboard testing.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That happens because of
colorize=True
. Loguru will add ansi codes to colorize your logs. However, these codes are only transformed to colors while inside a terminal.By default, if the
colorize
argument is not provided, Loguru tries to guess whether or not the sink (likesys.stderr
or a file) supports ansi codes and strip them out if it doesn’t. However as you specifiedcolorize=True
, Loguru will add them anyway. That’s why you’re seeing such symbols in your file.You can set
colorize=False
or just plainly omit this parameter and it should work fine. 😉Indeed, but look at where the
format_record
is used in the snippet you shared:This custom
format
is only used to configure thesys.stdout
handler. If you want the same format for the logs emitted to your file, you need to specify it while adding the file handler too. For example: