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

dictConfig in logconfig #1087

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

dictConfig in logconfig #1087

roboslone opened this issue Jul 20, 2015 · 13 comments

Comments

@roboslone
Copy link

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
Copy link
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
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Owner

benoitc commented Jul 22, 2015

+1 . Any PR is welcome :)

@MatMoore
Copy link
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
Copy link
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
Copy link
Contributor

@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
Copy link

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
Copy link
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
Copy link

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.

@gangefors
Copy link

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
Copy link
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 as completed Nov 4, 2017
@StephanErb
Copy link

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
Projects
None yet
Development

No branches or pull requests

10 participants