classification
Title: logging.config.fileConfig error
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: lukasz.langa Nosy List: Alzakath, eric.araujo, lukasz.langa, raduv
Priority: normal Keywords: patch

Created on 2013-03-18 07:34 by Alzakath, last changed 2013-05-21 12:34 by lukasz.langa. 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 "<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_""'
>>>
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
2013-05-21 12:34:50lukasz.langasetstatus: open -> closed
resolution: works for me
stage: resolved
2013-04-05 12:13:29Alzakathsetmessages: + msg186076
2013-04-02 12:38:46lukasz.langasetmessages: + msg185832
2013-03-30 19:35:38eric.araujosetnosy: + eric.araujo

messages: + msg185587
versions: - Python 3.2
2013-03-30 14:37:08vinay.sajipsetnosy: - vinay.sajip
2013-03-29 18:14:29vinay.sajipsetnosy: vinay.sajip, lukasz.langa, Alzakath, raduv
messages: + msg185509
2013-03-19 16:31:40lukasz.langasetassignee: lukasz.langa
versions: + Python 3.2, Python 3.4
2013-03-19 02:10:51r.david.murraysetnosy: + lukasz.langa
2013-03-19 00:34:16Alzakathsetmessages: + msg184568
2013-03-18 23:52:37raduvsetfiles: + issue17453.diff

nosy: + raduv
messages: + msg184558

keywords: + patch
2013-03-18 22:24:35vinay.sajipsetmessages: + msg184538
2013-03-18 16:18:53ned.deilysetnosy: + vinay.sajip
2013-03-18 07:34:49Alzakathcreate