Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow .json or .yaml --log-config files #665

Merged
merged 13 commits into from
Aug 18, 2020
Merged

Allow .json or .yaml --log-config files #665

merged 13 commits into from
Aug 18, 2020

Conversation

jcwilson
Copy link
Contributor

@jcwilson jcwilson commented May 3, 2020

This adds support for .json and .yaml config files when running uvicorn from the CLI.
This allows users to define how they wish to deal with existing loggers (#511, #512)
by providingdisable_existing_loggers in their config file (the last item described in this section).

Furthermore, it addresses the desire to allow users to replicate the default hard-coded
LOGGING_CONFIG in their own configs and tweak it as necessary, something that is not currently
possible for clients that wish to run their apps from the CLI.

This adds support for `.json` and `.yaml` config files when running `uvicorn`
from the CLI. This allows clients to define how they wish to deal with existing loggers (#511, #512)
by providing`disable_existing_loggers` in their config file (the last item described in
[this section](https://docs.python.org/3/library/logging.config.html#dictionary-schema-details)).

Furthermore, it addresses the desire to allow users to replicate the default hard-coded
`LOGGING_CONFIG` in their own configs and tweak it as necessary, something that is not currently
possible for clients that wish to run their apps from the CLI.
setup.py Outdated Show resolved Hide resolved
Copy link
Member

@euri10 euri10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows users to define how they wish to deal with existing loggers (#511, #512)
by providingdisable_existing_loggers in their config file (the last item described in this section.

I may be off on this but I thought that it was not possible to add that key to an ini file and that the only option if you want that behaviour was to pass it as a kwarg to fileConfig(), I don't think this PR solves anything from #511 but I admit I'm not sure about it, if it does it's cool.

otherwise LGTM minus few changes and @tomchristie thoughts on the extra_requires thing !

docs/settings.md Show resolved Hide resolved
requirements.txt Outdated Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
tests/test_config.py Show resolved Hide resolved
@jcwilson
Copy link
Contributor Author

jcwilson commented May 4, 2020

I may be off on this but I thought that it was not possible to add that key to an ini file and that the only option if you want that behaviour was to pass it as a kwarg to fileConfig(), I don't think this PR solves anything from #511 but I admit I'm not sure about it, if it does it's cool.

You're correct that it's not possible to disable existing loggers with a setting in the fileConfig() file, but one can with dictConfig(). So anyone wishing to disable existing loggers would switch to a json or yaml logging config and get the desired behavior without having to invoke uvicorn programmatically.

@jcwilson jcwilson requested a review from euri10 May 29, 2020 00:04
@jcwilson
Copy link
Contributor Author

@tomchristie @euri10 Can we merge this? I've backed out the changes that related to the "extras" decision. As it's implemented now, it expects the user to install a yaml library and there are code comments explaining how to address the situation if it's missing.

Copy link
Member

@euri10 euri10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor changes to be made I think, my fault because it's been a while since you posted this, I hope you dont mind, let me know if you want me to take this on

  1. the pip install uvicorn[yamllogconfig] is obsolete in settings.md
  2. we would need a section in the README.md about this, after the python-dotenv part this should do it
  3. add pyyaml in the setup.py so that we have it when using uvicorn[standard]

otherwise this is great stuff

docs/settings.md Outdated
Comment on lines 37 to 42
* If you wish to use a YAML file for your logging config, you will want to specify the optional `yamllogconfig` dependency to ensure YAML support:

```
$ pip install uvicorn[yamllogconfig]
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry to get back on this that late :) time flies, work is insane,

we can remove this part now package install is merged

requirements.txt Outdated Show resolved Hide resolved
@euri10
Copy link
Member

euri10 commented Aug 13, 2020

I pushed https://github.com/euri10/uvicorn/tree/jcwilson-master based on your work and making the changes so that it doesnt clash with latest master here @jcwilson
Cant push into your PR unfortunately or there are some git commands I'm missing so feel free to take the necessary commits !

@jcwilson
Copy link
Contributor Author

Sorry for not getting back to you earlier last week. I think I've made all the changes you've requested. Let me know if there's anything else and I should be able to address it tomorrow. Thanks!

@euri10 euri10 merged commit 093a1f7 into encode:master Aug 18, 2020
@euri10
Copy link
Member

euri10 commented Aug 18, 2020

thanks for your contribution @jcwilson this is a great addition 💯 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants