-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
logging.config.fileConfig error #61655
Comments
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 "<stdin>", line 1, in <module>
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_""'
>>> |
What is your intent in setting up a configuration like that? How do you expect it to behave? |
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). |
My complete configuration is this: [loggers] 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. |
Removing myself from nosy, as it appears to be a ConfigParser issue. |
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". |
Treating "" as empty values was a bug in configparser pre 3.2 (it made it impossible to store "" as a value). Simply change [section] to [section] Does that solve your problem? |
Yes it does. I fixed my configuration generation and everything is running as expected. Thanks. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: