This is a template for creating a FastAPI application with logging and a database connection setup.
- Run
uvicorn main:app --reload
from the app directory - Use the pycharm runtime
uvicorn
to start up the application
- Ensure you have python3.9 installed
python3 --version
orpython3.9 --version
- Install pipenv (preferably with pipx)
python3 -m pip install pipx
pipx install pipenv
pipenv install --dev
from the mercury directorypre-commit install
pre-commit run --all-files
- (Optional) in Pycharm -> Preferences -> Project add the venv (found at
pipenv --venv
)
- Run
pytest
for a basic check - Run
pytest --cov=app
to get a coverage report - Run
pytest --cov=app --cov-report html
to get a html version of the report that is navigable.
The logs are stored as json in order to be able to parse them with jq or pass them to another system in the future. Below are several examples of how you can parse the logs.
- Get all logs that are created with the
app.logger.log
functionscat logs/app.log | jq 'select(.request_id | contains("None"))
- The same as above but get just the message
cat logs/app.log | jq 'select(.request_id | contains("None")) | .message' | jq -r
- Get all the http responses created by uvicorn
tail logs/app.log | jq -r 'select(.name | contains("h11_impl")) | .message'