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

dictConfig in logconfig #1087

Closed
roboslone opened this Issue Jul 20, 2015 · 13 comments

Comments

10 participants
@roboslone

roboslone commented Jul 20, 2015

From logging docs:

Note: The fileConfig() API is older than the dictConfig() API and does not provide functionality to cover certain aspects of logging. For example, you cannot configure Filter objects, which provide for filtering of messages beyond simple integer levels, using fileConfig(). If you need to have instances of Filter in your logging configuration, you will need to use dictConfig(). Note that future enhancements to configuration functionality will be added to dictConfig(), so it’s worth considering transitioning to this newer API when it’s convenient to do so.

Could you suppport dictConfig in logconfig option?

@tilgovi

This comment has been minimized.

Collaborator

tilgovi commented Jul 20, 2015

Can you confirm what you mean. Having a dictionary somehow in the command line with --log-config, is not what you want, correct? But a dictionary when using the logconfig setting in your gunicorn conf python file you want to set a dictionary?

@roboslone

This comment has been minimized.

roboslone commented Jul 21, 2015

My application reads config from file and part of this config is for logging. I want to pass that part to dictConfig. I'm not using command line arguments for logging config at all.

@berkerpeksag

This comment has been minimized.

Collaborator

berkerpeksag commented Jul 21, 2015

Looks like a reasonable request to me. I think we can also deprecate logconfig (or encourage to use the new setting) and add a new setting for this.

@benoitc

This comment has been minimized.

Owner

benoitc commented Jul 22, 2015

+1 . Any PR is welcome :)

@MatMoore

This comment has been minimized.

Contributor

MatMoore commented Sep 3, 2015

Hello - I'm also interested in this feature. Is the PR above similar to what you had in mind?

@benoitc

This comment has been minimized.

Owner

benoitc commented Dec 23, 2015

I fail to see how the command line can be used. Can someone provide a proper example? And test?

@MatMoore

This comment has been minimized.

Contributor

MatMoore commented Dec 24, 2015

@benoitc is a CLI option needed for every setting? It's not something I've addressed in the pull request above - that just works with the python configuration file.

If it was a CLI option, how would you use it? The only way I could see it working is if the value is dumped in a json or yaml file and the filename is used as the setting, but that just makes things more complicated if you are already using the python config.

@akaihola

This comment has been minimized.

akaihola commented Sep 2, 2016

Maybe the way Circus handles logging configuration could be used as a model? See circus/util.py:configure_logger().

@benoitc

This comment has been minimized.

Owner

benoitc commented Sep 2, 2016

@akaihola how is it different from the way we are doing it now? Also we should not forget that the logging backend is pluggable in Gunicorn.

@ssalonen

This comment has been minimized.

ssalonen commented Sep 2, 2016

I found a workaround using --config parameter: one can use dictConfig there to setup the logging.

At least seems to work with the default worker type.

@benoitc benoitc added this to Other in Mailing List Feb 26, 2017

@gangefors

This comment has been minimized.

gangefors commented Aug 15, 2017

@ssalonen
I found a workaround using --config parameter: one can use dictConfig there to setup the logging.

At least seems to work with the default worker type.

I figured out how to do this for dictConfig using a json config file.

In your gunicorn config.py file you put the following code.

import json
import logging.config

with open('/path/to/logging.conf') as conf_file:
    logging.config.dictConfig(json.load(conf_file))

bind = "0.0.0.0:5000"
(the rest of your gunicorn config settings)

Then start with gunicorn -c config.py app:app

This should let you configure your logging using a json file instead of the default INI format.
Or you can put the logging config as a dict directly in the config.py file.

@wking

This comment has been minimized.

Contributor

wking commented Nov 3, 2017

Closable with #1602 landed, or is this staying open until a release is cut including #1602?

@tilgovi tilgovi closed this Nov 4, 2017

@StephanErb

This comment has been minimized.

StephanErb commented Nov 14, 2017

Please excuse my ignorance, but I am slightly confused how #1602 enables me to load a dict config via the gunicorn command line:

$ gunicorn --log-config-dict={} 'flask.main:app'
Error: Value is not a dictionary: {}

$ gunicorn --log-config-dict="{}" 'flask.main:app'
Error: Value is not a dictionary: {}

What am I missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment