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

Created on 30 Oct 2018  路  11Comments  路  Source: benoitc/gunicorn

Despite https://github.com/benoitc/gunicorn/issues/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).

( Documentation

Most helpful comment

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.

All 11 comments

what error do you have? how to reproduce it?

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.

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

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']}}"

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.

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

CLI option was added in c5ae962dfa3c9a84dfef3af386c7b4f282d02e6e . 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.

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

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

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

Was this page helpful?
0 / 5 - 0 ratings