Adding support for .json and .yaml --log-config files

I was about to click “Create pull request” in github with some changes I thought would be well received, but then saw the “Maintainer driven issues” request in the contributing guidelines, so here I am. :slight_smile:

My use case is that I wish to run my app using the uvicorn command line option but also specify a custom logging config. This means --log-config must currently point to a file using the limited and apparently deprecated configparser format as uvicorn uses the fileConfig() function.

It appeared to be pretty trivial to add support for loading a JSON or YAML config so that one could hand it off to dictConfig(), so I went ahead and did that work on my fork here. You can see from the commit message that it addresses a couple of other currently open issues.

The changes should be backwards-compatible with existing installations, as it only attempts to load the json or yaml files if the indicated file has the appropriate filename extension. If not, it falls back to the current behavior where the configparser format is assumed. However, it will now emit a warning letting the client know that they can/should update to the new format so we can hopefully remove the fileConfig() functionality in the future.

Any thoughts?

Hello, I only can offer my good thoughts in agreement.

I am looking for a clean way to do this myself, as I’d prefer us using the YAML (or JSON) instead of the INI. Or if we could programatically set it as we want, that’d be good too.

perhaps the question is should we start uvicorn in that case as
uvicorn or via python command?