Error when using formater JSONFormatter in Python3.5

Bug #1739743 reported by Suff
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo.log
Fix Released
Medium
Stephen Finucane

Bug Description

In Python3.5 was added new argument for _create_formatters() function in /usr/lib/python3.5/logging/config.py. Now, before formatter was returned, logging.Formatter takes obvious style argument. (f = c(fs, dfs, stl)).
When we are using JSONFormatter, we get traceback.

Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.5/nova-api", line 10, in <module>
    sys.exit(main())
  File "/usr/lib64/python3.5/site-packages/nova/cmd/api.py", line 41, in main
    logging.setup(CONF, "nova")
  File "/usr/lib64/python3.5/site-packages/oslo_log/log.py", line 262, in setup
    _load_log_config(conf.log_config_append)
  File "/usr/lib64/python3.5/site-packages/oslo_log/log.py", line 223, in _load_log_config
    disable_existing_loggers=False)
  File "/usr/lib64/python3.5/logging/config.py", line 76, in fileConfig
    formatters = _create_formatters(cp)
  File "/usr/lib64/python3.5/logging/config.py", line 125, in _create_formatters
    f = c(fmt=fs, datefmt=dfs, style=stl)
TypeError: __init__() got an unexpected keyword argument 'style'

For current working, __init__ in JSONFormatter class must takes style argument.

Tags: python3.5
Revision history for this message
Suff (dmitry-a-grachev) wrote :
Revision history for this message
Doug Hellmann (doug-hellmann) wrote :

I think that patch looks correct. Are you set up so you can submit it via gerrit instead of as an attachment here?

Revision history for this message
Suff (dmitry-a-grachev) wrote :

Yes, I can try it.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to oslo.log (master)

Fix proposed to branch: master
Review: https://review.openstack.org/534658

Changed in oslo.log:
status: New → In Progress
importance: Undecided → Medium
assignee: nobody → Suff (dmitry-a-grachev)
Changed in oslo.log:
assignee: Suff (dmitry-a-grachev) → Stephen Finucane (stephenfinucane)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to oslo.log (master)

Reviewed: https://review.openstack.org/534658
Committed: https://git.openstack.org/cgit/openstack/oslo.log/commit/?id=89bbb3fb79ecfa45ed41afee86900131b3e37dc6
Submitter: Zuul
Branch: master

commit 89bbb3fb79ecfa45ed41afee86900131b3e37dc6
Author: Suff <email address hidden>
Date: Wed Jan 17 10:47:11 2018 +0300

    Fix Formatter subclasses for Python 3.2+

    Python 3.2 added the 'style' parameter to 'logging.Formatter.__init__'.
    This is provided by 'logging.config.fileConfig' meaning this currently
    raises a 'TypeError' similar to the below when the incompatible
    formatters, JSONFormatter and FluentFormatter, are used with Python 3.2
    or greater.

      TypeError: __init__() got an unexpected keyword argument 'style'

    Resolve this by simply adding the parameter to the list. There is more
    work we can do here (like actually supporting this parameter) but that's
    a job for another patch.

    Note that we can't actually test this as doing so would involve invoking
    'logging.config.fileConfig', which in turn would modify the global state
    of the 'logging' module. You can thank the singleton pattern for that.

    Change-Id: I9b339163ddfe440bc6782ced33595a0dcf60f658
    Closes-Bug: 1739743
    Co-Authored-By: Stephen Finucane <email address hidden>

Changed in oslo.log:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.