Issue 17453: logging.config.fileConfig error - Python tracker (original) (raw)

Created on 2013-03-18 07:34 by Alzakath, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue17453.diff raduv,2013-03-18 23:52 review
Messages (8)
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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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.
History
Date User Action Args
2022-04-11 14:57:43 admin set github: 61655
2013-05-21 12:34:50 lukasz.langa set status: open -> closedresolution: works for mestage: resolved
2013-04-05 12:13:29 Alzakath set messages: +
2013-04-02 12:38:46 lukasz.langa set messages: +
2013-03-30 19:35:38 eric.araujo set nosy: + eric.araujomessages: + versions: - Python 3.2
2013-03-30 14:37:08 vinay.sajip set nosy: - vinay.sajip
2013-03-29 18:14:29 vinay.sajip set nosy:vinay.sajip, lukasz.langa, Alzakath, raduvmessages: +
2013-03-19 16:31:40 lukasz.langa set assignee: lukasz.langaversions: + Python 3.2, Python 3.4
2013-03-19 02:10:51 r.david.murray set nosy: + lukasz.langa
2013-03-19 00:34:16 Alzakath set messages: +
2013-03-18 23:52:37 raduv set files: + issue17453.diffnosy: + raduvmessages: + keywords: + patch
2013-03-18 22:24:35 vinay.sajip set messages: +
2013-03-18 16🔞53 ned.deily set nosy: + vinay.sajip
2013-03-18 07:34:49 Alzakath create