msg184435 - (view) |
Author: Hervé Coatanhay (Alzakath) * |
Date: 2013-03-18 07:34 |
In python 2.7 this code works: >>> import logging.config >>> import StringIO >>> a="""[loggers] ... keys = root ... [logger_root] ... handlers = "" ... [formatters] ... keys = "" ... [handlers] ... keys = "" ... """ >>> logging.config.fileConfig(StringIO.StringIO(a)) >>> whereas in python 3.3 it raises an exception: >>> import logging.config >>> import io >>> a="""[loggers] ... keys = root ... [logger_root] ... handlers = "" ... [formatters] ... keys = "" ... [handlers] ... keys = "" ... """ >>> logging.config.fileConfig(io.StringIO(a)) Traceback (most recent call last): File "", line 1, in File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/logging/config.py", line 70, in fileConfig formatters = _create_formatters(cp) File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/logging/config.py", line 114, in _create_formatters class_name = cp[sectname].get("class") File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/configparser.py", line 942, in __getitem__ raise KeyError(key) KeyError: 'formatter_""' >>> |
|
|
msg184538 - (view) |
Author: Vinay Sajip (vinay.sajip) *  |
Date: 2013-03-18 22:24 |
What is your intent in setting up a configuration like that? How do you expect it to behave? |
|
|
msg184558 - (view) |
Author: Radu Voicilas (raduv) |
Date: 2013-03-18 23:52 |
Even though it seems kind of weird to have all those keys set to the empty string, I still think that configparser should handle this case, which might be relevant for some other uses cases (not logging configs). The attached patch should take care of this. |
|
|
msg184568 - (view) |
Author: Hervé Coatanhay (Alzakath) * |
Date: 2013-03-19 00:34 |
My complete configuration is this: [loggers] keys = app_admin,root,app_test_py3 [logger_root] handlers = "" [formatters] keys = app_admin,app_test_py3 [handlers] keys = app_admin,app_test_py3 [logger_app_admin] propagate = 1 handlers = app_admin qualname = nagare.application.admin level = INFO [handler_app_admin] formatter = app_admin class = StreamHandler args = (sys.stderr,) [formatter_app_admin] format = %(asctime)s - %(name)s - %(levelname)s - %(message)s [logger_app_test_py3] propagate = 1 handlers = app_test_py3 qualname = nagare.application.test_py3 level = INFO [formatter_app_test_py3] format = %(asctime)s - %(name)s - %(levelname)s - %(message)s [handler_app_test_py3] formatter = app_test_py3 class = StreamHandler args = (sys.stderr,) I wanted to provided a non-working configuration as small as possible, that was accepted by python 2.7. It seems you are right there is a problem with this configuration as it shuts down logging in python 2.7. It looks like i have a bug in my configuration generation. By the way the patch restores python 2.7 behavior as expected, thanks. |
|
|
msg185509 - (view) |
Author: Vinay Sajip (vinay.sajip) *  |
Date: 2013-03-29 18:14 |
Removing myself from nosy, as it appears to be a ConfigParser issue. |
|
|
msg185587 - (view) |
Author: Éric Araujo (eric.araujo) *  |
Date: 2013-03-30 19:35 |
Unless the 2.7 configparser docs mention that two quotes are parsed as an empty string, I think this is an implementation accident, should not be relied upon and 3.x should not be changed to match it. Values in configparser files are not Python strings: we write root, not "root". |
|
|
msg185832 - (view) |
Author: Łukasz Langa (lukasz.langa) *  |
Date: 2013-04-02 12:38 |
Treating "" as empty values was a bug in configparser pre 3.2 (it made it impossible to store "" as a value). Simply change [section] option = "" to [section] option = Does that solve your problem? |
|
|
msg186076 - (view) |
Author: Hervé Coatanhay (Alzakath) * |
Date: 2013-04-05 12:13 |
Yes it does. I fixed my configuration generation and everything is running as expected. Thanks. |
|
|