summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuff <dmitry.a.grachev@gmail.com>2018-01-17 10:47:11 +0300
committerStephen Finucane <sfinucan@redhat.com>2018-05-03 10:16:09 +0100
commit89bbb3fb79ecfa45ed41afee86900131b3e37dc6 (patch)
tree0d3f70ace1205f023853d5b68916e1037c5df5d8
parent33b5b3fc47f2729b685a2edbb37502d3f186cf92 (diff)
downloadoslo-log-89bbb3fb79ecfa45ed41afee86900131b3e37dc6.tar.gz
Fix Formatter subclasses for Python 3.2+3.38.1
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 <stephenfin@redhat.com>
-rw-r--r--oslo_log/formatters.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/oslo_log/formatters.py b/oslo_log/formatters.py
index 9277856..2545035 100644
--- a/oslo_log/formatters.py
+++ b/oslo_log/formatters.py
@@ -181,9 +181,10 @@ class _ReplaceFalseValue(dict):
class JSONFormatter(logging.Formatter):
- def __init__(self, fmt=None, datefmt=None):
- # NOTE(jkoelker) we ignore the fmt argument, but its still there
- # since logging.config.fileConfig passes it.
+ def __init__(self, fmt=None, datefmt=None, style='%'):
+ # NOTE(sfinucan) we ignore the fmt and style arguments, but they're
+ # still there since logging.config.fileConfig passes the former in
+ # Python < 3.2 and both in Python >= 3.2
self.datefmt = datefmt
try:
self.hostname = socket.gethostname()
@@ -277,9 +278,9 @@ class FluentFormatter(logging.Formatter):
.. versionadded:: 3.17
"""
- def __init__(self, fmt=None, datefmt=None):
- # NOTE(masaki) we ignore the fmt argument because of the same reason
- # with JSONFormatter.
+ def __init__(self, fmt=None, datefmt=None, style='%s'):
+ # NOTE(sfinucan) we ignore the fmt and style arguments for the same
+ # reason as JSONFormatter.
self.datefmt = datefmt
try:
self.hostname = socket.gethostname()