-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Support Dictionary Config setting. #1602
Conversation
gunicorn/glogging.py
Outdated
if dictConfig and cfg.logconfig_dict: | ||
config = CONFIG_DEFAULTS.copy() | ||
config.update(cfg.logconfig_dict) | ||
dictConfig(config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably need to catch the following exceptions and raise RuntimeError(message_from_catched_exception)
like we already did for logconfig
in line 247:
If an error is encountered during configuration, this function will raise a ValueError, TypeError, AttributeError or ImportError with a suitably descriptive message.
gunicorn/config.py
Outdated
validator = validate_dict | ||
default = {} | ||
desc = """\ | ||
The log config dictionary to use, using the standard Python logging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add a versionadded
label.
gunicorn/config.py
Outdated
default = {} | ||
desc = """\ | ||
The log config dictionary to use, using the standard Python logging | ||
module's dictConfig format added in python 2.7. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dictConfig -> ``dictConfig``
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need add a link to https://docs.python.org/3/library/logging.config.html#logging.config.dictConfig
gunicorn/config.py
Outdated
desc = """\ | ||
The log config dictionary to use, using the standard Python logging | ||
module's dictConfig format added in python 2.7. | ||
If available, this takes precedence over logconfig, which uses the older |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logconfig -> :ref:`--log-config `
gunicorn/config.py
Outdated
The log config dictionary to use, using the standard Python logging | ||
module's dictConfig format added in python 2.7. | ||
If available, this takes precedence over logconfig, which uses the older | ||
fileConfig format. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fileConfig -> ``fileConfig``
@@ -1309,6 +1309,19 @@ class LogConfig(Setting): | |||
""" | |||
|
|||
|
|||
class LogConfigDict(Setting): | |||
name = "logconfig_dict" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add cli = ["--log-config-dict"]
?
gunicorn/config.py
Outdated
default = {} | ||
desc = """\ | ||
The log config dictionary to use, using the standard Python logging | ||
module's dictConfig format added in python 2.7. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better to remove "added in python 2.7" and print a warning if dictConfig
is None
in gunicorn/glogging.py
.
a12b878
to
783c9be
Compare
@berkerpeksag I think I addressed all your comments. Thanks for the review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left two comments but they aren't blockers and can be addressed in separate PRs. Thanks!
section = "Logging" | ||
cli = ["--log-config-dict"] | ||
validator = validate_dict | ||
default = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a little bit misleading since we use glogging.CONFIG_DEFAULTS
as default. Should we document this or keep it as implementation detail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should set the default as None
? Would that be more "unset" / "undefined" / "default" to people?
Maybe it doesn't matter much either way.
desc = """\ | ||
The log config dictionary to use, using the standard Python | ||
logging module's dictionary configuration format. This option | ||
takes precedence over the :ref:`logconfig` option, which uses the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a minor issue, but I'd say let's deprecate --log-config
documentation-only and tell users to switch to --log-config-dict
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can explain a bit more, I will do a PR. Or I will review a PR. Thanks!
Support Dictionary Config setting.
class LogConfigDict(Setting): | ||
name = "logconfig_dict" | ||
section = "Logging" | ||
cli = ["--log-config-dict"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to work, as there doesn't seem to be any conversion from the string supplied by the shell in some ARGV[x]
to an actual dict:
bash-3.2$ env/bin/gunicorn --version
env/bin/gunicorn --version
gunicorn (version 19.9.0)
bash-3.2$ env/bin/gunicorn --log-config-dict {} 'flask.main:app'
env/bin/gunicorn --log-config-dict {} 'flask.main:app'
Error: Value is not a dictionary: {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, maybe cli
should have been left off this option until someone JSON-parses it. Can you use config file?
Also https://stackoverflow.com/a/18609361/452210 re argparse
capabilities in this area.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can extend our config we're passing via --config=python:cariumlib.djangolib.gunicorn_config
It's funny, I tried hacking type=json.loads
in, but couldn't get it to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could convert your PR comment into a new issue along the lines of advertised CLI option --log-config-dict
cannot work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javabrett Done: #1909
Taking over #1110 as per the OP request.