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

logging.config.fileConfig error #61655

Closed
Alzakath mannequin opened this issue Mar 18, 2013 · 8 comments
Closed

logging.config.fileConfig error #61655

Alzakath mannequin opened this issue Mar 18, 2013 · 8 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@Alzakath
Copy link
Mannequin

Alzakath mannequin commented Mar 18, 2013

BPO 17453
Nosy @merwok, @ambv
Files
  • issue17453.diff
  • 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:

    assignee = 'https://github.com/ambv'
    closed_at = <Date 2013-05-21.12:34:50.056>
    created_at = <Date 2013-03-18.07:34:49.571>
    labels = ['type-bug', 'library']
    title = 'logging.config.fileConfig error'
    updated_at = <Date 2013-05-21.12:34:50.055>
    user = 'https://bugs.python.org/Alzakath'

    bugs.python.org fields:

    activity = <Date 2013-05-21.12:34:50.055>
    actor = 'lukasz.langa'
    assignee = 'lukasz.langa'
    closed = True
    closed_date = <Date 2013-05-21.12:34:50.056>
    closer = 'lukasz.langa'
    components = ['Library (Lib)']
    creation = <Date 2013-03-18.07:34:49.571>
    creator = 'Alzakath'
    dependencies = []
    files = ['29466']
    hgrepos = []
    issue_num = 17453
    keywords = ['patch']
    message_count = 8.0
    messages = ['184435', '184538', '184558', '184568', '185509', '185587', '185832', '186076']
    nosy_count = 4.0
    nosy_names = ['eric.araujo', 'lukasz.langa', 'Alzakath', 'raduv']
    pr_nums = []
    priority = 'normal'
    resolution = 'works for me'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue17453'
    versions = ['Python 3.3', 'Python 3.4']

    @Alzakath
    Copy link
    Mannequin Author

    Alzakath mannequin commented Mar 18, 2013

    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_""'
    >>>

    @Alzakath Alzakath mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 18, 2013
    @vsajip
    Copy link
    Member

    vsajip commented Mar 18, 2013

    What is your intent in setting up a configuration like that? How do you expect it to behave?

    @raduv
    Copy link
    Mannequin

    raduv mannequin commented Mar 18, 2013

    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.

    @Alzakath
    Copy link
    Mannequin Author

    Alzakath mannequin commented Mar 19, 2013

    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.

    @ambv ambv self-assigned this Mar 19, 2013
    @vsajip
    Copy link
    Member

    vsajip commented Mar 29, 2013

    Removing myself from nosy, as it appears to be a ConfigParser issue.

    @merwok
    Copy link
    Member

    merwok commented Mar 30, 2013

    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".

    @ambv
    Copy link
    Contributor

    ambv commented Apr 2, 2013

    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?

    @Alzakath
    Copy link
    Mannequin Author

    Alzakath mannequin commented Apr 5, 2013

    Yes it does. I fixed my configuration generation and everything is running as expected.

    Thanks.

    @ambv ambv closed this as completed May 21, 2013
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants