add logging overriding
sometimes its nice to have your custom logging in fastapi so i added passing it to uvicorn and fallbacking to uvicorn default one if nothing is passed in
+1
+1
+1
+1
@wchaws can you please add tag feature to fix failing test? thanks
@07pepa I'm not the maintainer for this project. I just accidentally approved this PR.
ok i thought you would have some extra rights if you could approve
+1
Is this PR just missing label "feature"? @07pepa @wchaws Are you able to add it?
Thanks
Is this PR just missing label "feature"? @07pepa @wchaws Are you able to add it?
Thanks
Yes i am unable as author of PR to change/add label. Label is only thing that is missing.
i tried even modifying labeler and no luck https://github.com/fastapi/fastapi-cli/pull/110
we probably need to ask @tiangolo how to do this (or to add label)
+1
Hihi all, is anybody looking into fixing the labeler issue? Thanks
@mapapa i can't
Can you please help this feature to go through @tiangolo? it's very annoying to see unnecessary access logs in production servers
+1 I need ECS logging for fastapi run
Any updates here ? Could I take over if I need this functionality ? What is the problem with labels ?
Any updates here ? Could I take over if I need this functionality ? What is the problem with labels ?
this is problem with labes https://github.com/fastapi/fastapi-cli/actions/runs/13716548094/job/38362509674?pr=36
also problem here https://github.com/fastapi/fastapi-cli/pull/160 probably we need acces to repo to add labels
@darowny you can take over
+1 i really need to change the uvicorn log level because some path like readiness and liveness in k8s are called every few seconds and the exception will "disappear" inside the logs after few minutes. (also the possibility to have change the log only for specific paths should be nice. don't know if uvicorn support something similar or should be done in fastapi code)
+1 I also need this as the default logger doesn't have timestamps. When errors occur, it makes troubleshooting much more difficult. There are workarounds, but being able to specify a logging override would be the easiest method.
I too would love to be able to override the logger - I'd like to be able to use the same formatter that's used for my application code. Especially the lack of timestamps for access logs is quite annoying.
This pull request has a merge conflict that needs to be resolved.
+1, imo this is what stops this wrapper from being genuinely production-ready.
Following up on my previous comment saying that after some studies I will suggest for production service to avoid fastapi-cli installing fastapi and uvicorn without fastapi[standard] or other versions.
You can create the main.py file with explicit uvicorn configuration:
import uvicorn
uvicorn.run(
"app_folder.app_creator:app",
host=<host>, # example: "0.0.0.0"
port=<port>, # example: 8080
workers=<workers>, # example: 3
reload=<reload>, # false in production
log_config=<logging_config dict> # Optional
)
- I suggest to use
pydantic-settingsto create a configuration object containing all the parameters in order to be flexible with different configuration sources having a type validation logging_config dictfollow the python logging standard configuration that can be found here. In this way you can have a clean cli that is much readable server-side and you can set up other handlers like jsonl file or more fancy handlers. In my case I set up a clean and minimal cli log without fancy lines and similar stuff, plus a jsonl like handler that split the file by level and rotate them, all the handlers managed by a queue handler that process them in a separated thread in order to avoid api performance issues.
In app_creator.py create your FastAPI app with all necessary components like lifespan, routers, middleware etc.
Something similar to:
from fastapi import FastAPI
app = FastAPI(
title="Your API",
# all needed parameters and configurations
)
# Add routers, middleware, exception handlers, etc.
app.include_router(your_router)