Skip to content
This repository was archived by the owner on Dec 21, 2024. It is now read-only.

Commit 8abb283

Browse files
committed
Merge branch 'master' into mypy
2 parents 4c72bed + b70941b commit 8abb283

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,5 @@ External Examples
170170
=================
171171

172172
- [Wesley Tanaka - Structured log files in Python using python-json-logger](https://wtanaka.com/node/8201)
173+
174+
- [Archive](https://web.archive.org/web/20201130054012/https://wtanaka.com/node/8201)

src/pythonjsonlogger/jsonlogger.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,18 @@ def parse(self) -> List[str]:
146146
147147
This method is responsible for returning a list of fields (as strings)
148148
to include in all log messages.
149-
"""
150-
standard_formatters = re.compile(r'\((.+?)\)', re.IGNORECASE)
151-
152-
if self._fmt:
153-
return standard_formatters.findall(self._fmt)
149+
"""
150+
if isinstance(self._style, logging.StringTemplateStyle):
151+
formatter_style_pattern = re.compile(r'\$\{(.+?)\}', re.IGNORECASE)
152+
elif isinstance(self._style, logging.StrFormatStyle):
153+
formatter_style_pattern = re.compile(r'\{(.+?)\}', re.IGNORECASE)
154+
# PercentStyle is parent class of StringTemplateStyle and StrFormatStyle so
155+
# it needs to be checked last.
156+
elif isinstance(self._style, logging.PercentStyle):
157+
formatter_style_pattern = re.compile(r'%\((.+?)\)s', re.IGNORECASE)
154158
else:
155-
return []
159+
raise ValueError('Invalid format: %s' % self._fmt)
160+
return formatter_style_pattern.findall(self._fmt)
156161

157162
def add_fields(self, log_record, record, message_dict):
158163
"""

0 commit comments

Comments
 (0)