This repository was archived by the owner on Dec 21, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -170,3 +170,5 @@ External Examples
170
170
=================
171
171
172
172
- [ 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 )
Original file line number Diff line number Diff line change @@ -146,13 +146,18 @@ def parse(self) -> List[str]:
146
146
147
147
This method is responsible for returning a list of fields (as strings)
148
148
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 )
154
158
else :
155
- return []
159
+ raise ValueError ('Invalid format: %s' % self ._fmt )
160
+ return formatter_style_pattern .findall (self ._fmt )
156
161
157
162
def add_fields (self , log_record , record , message_dict ):
158
163
"""
You can’t perform that action at this time.
0 commit comments