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

log-config-dict cli option is broken, can't work as coded. #1909

Closed
rthille opened this issue Oct 30, 2018 · 11 comments · Fixed by #2476
Closed

log-config-dict cli option is broken, can't work as coded. #1909

rthille opened this issue Oct 30, 2018 · 11 comments · Fixed by #2476

Comments

@rthille
Copy link

rthille commented Oct 30, 2018

Despite #1880 being closed, the --log-config-dict cli option is broken and can't work as coded because the CLI's type member isn't set, so the dict_validator tries to validate a string (what's coming from ARGV), unconverted, and that fails.
I tried hacking the code to use type = json.loads so that the string would be converted to a dict by ArgParse, but couldn't make that work either. (I think that can work, I was just screwing something up I'm guessing).

@benoitc
Copy link
Owner

benoitc commented Nov 23, 2018

what error do you have? how to reproduce it?

@benoitc benoitc self-assigned this Nov 23, 2018
@rthille
Copy link
Author

rthille commented Nov 26, 2018

Just try starting gunicorn with the --log-config-dict option and some argument. It will always fail.

# gunicorn --log-config-dict '{}' integrator.settings.wsgi:application --bind=0.0.0.0:8080 --workers=3 --config python:cariumlib.djangolib.gunicorn_config
Error: Value is not a dictionary: {} 
# gunicorn --log-config-dict {} integrator.settings.wsgi:application --bind=0.0.0.0:8080 --workers=3 --config python:cariumlib.djangolib.gunicorn_config
Error: Value is not a dictionary: {} 
# 

There's no way to pass a python dict from the shell. You can only pass a string, and the code in gunicorn isn't setup to do the conversion from the string representation of the dict to the python dict object.

@benoitc
Copy link
Owner

benoitc commented Nov 27, 2018

afaik i'm not sure what is expected to pass on the command line there. Giving a dict as a string seems odd. cc @berkerpeksag @tilgovi

@rthille
Copy link
Author

rthille commented Nov 28, 2018

It seems like something like a json-encoded dict should be accepted:

gunicorn --log-config-dict "{'formatters': {'verbose': {'format': '\n%(levelname)s %(process)d %(asctime)s %(name)s %(pathname)s:%(lineno)d %(message)s'}},'handlers': {'console': {'class': 'logging.StreamHandler','formatter': 'verbose'}},'root': {'level': 'WARNING', 'handlers': ['console']}}"

@berkerpeksag
Copy link
Collaborator

I think logconfig_dict meant to be used in a configuration file. We need a way to disable a setting to be used via CLI.

In any case, we need to improve the logconfig_dict documentation with a note about using it via a configuration file and provide an example to show how to extend the logging configuration.

@berkerpeksag
Copy link
Collaborator

By the way, the following configuration file worked for me:

logconfig_dict = {
    'formatters': {
        'verbose': {
            'format': 'XXX %(levelname)s %(process)d %(asctime)s %(name)s %(pathname)s:%(lineno)d %(message)s',
        },
        'generic': {
            'format': '%(asctime)s [%(process)d] [%(levelname)s] %(message)s',
            'datefmt': '[%Y-%m-%d %H:%M:%S %z]',
        },
    },
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
            'formatter': 'verbose',
        },
        'error_console': {
            'class': 'logging.StreamHandler',
            'formatter': 'generic',
            'stream': 'ext://sys.stderr',
        },
    },
    'version': 1,
    'disable_existing_loggers': False,
}

It can be tested as follows:

$ cd gunicorn/examples
$ gunicorn -c ../conf.py test:app

@javabrett
Copy link
Collaborator

CLI option was added in c5ae962 . See also #1775. Probably needs comment/review/docnote from @tilgovi as to how the CLI option can/should work, or if it can't it is easily reverted.

@naringas
Copy link

gunicorn --help shows --logging-config-dict as an option but turns out that --logging-config-dict is useless as a command line flag

so I suggest either of these options

  1. remove --logging-config-dict from the cli
  2. make it accept a string. e.g. gunicorn --log-config-dict='{}' ... doesn't error out

@benoitc
Copy link
Owner

benoitc commented Oct 30, 2019

i would go for (1) , can you provide a PR for it?

@ruloweb
Copy link

ruloweb commented Sep 1, 2020

In the version 20.0.4 I can see the --logging-config-dict option, is this going to be removed?

tilgovi added a commit that referenced this issue Dec 16, 2020
There is no support for decoding any dictionary supplied on the command
line. The only way to supply a dictionary logging config is through the
configuration file.

Close #1909.
@tilgovi
Copy link
Collaborator

tilgovi commented Dec 16, 2020

#2476

tilgovi added a commit that referenced this issue Dec 19, 2020
There is no support for decoding any dictionary supplied on the command
line. The only way to supply a dictionary logging config is through the
configuration file.

Close #1909.
PetrDlouhy pushed a commit to PetrDlouhy/gunicorn that referenced this issue Oct 21, 2022
There is no support for decoding any dictionary supplied on the command
line. The only way to supply a dictionary logging config is through the
configuration file.

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

Successfully merging a pull request may close this issue.

7 participants