-
Notifications
You must be signed in to change notification settings - Fork 8
[core] Add support for comma format #54
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
base: nhairs-log-record
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,6 +175,12 @@ def __init__( | |
- Renaming fields now preserves the order that fields were added in and avoids adding | ||
missing fields. The original behaviour, missing fields have a value of `None`, is still | ||
available by setting `rename_fields_keep_missing` to `True`. | ||
|
||
*Added in 4.0*: | ||
|
||
- `fmt` now supports comma seperated lists (`style=","`). Note that this style is specific | ||
to `python-json-logger` and thus care should be taken to not to pass this format to other | ||
logging Formatter implementations. | ||
""" | ||
## logging.Formatter compatibility | ||
## --------------------------------------------------------------------- | ||
|
@@ -186,7 +192,7 @@ def __init__( | |
self._style = _style | ||
self._fmt = _style._fmt | ||
|
||
elif not validate: | ||
elif style == "," or not validate: | ||
self._style = style | ||
self._fmt = fmt | ||
|
||
|
@@ -271,6 +277,18 @@ def parse(self) -> List[str]: | |
Returns: | ||
list of fields to be extracted and serialized | ||
""" | ||
if self._fmt is None: | ||
# TODO: does it matter that we do this before checking if the style is valid? | ||
# (we already (mostly) check for valid style names in __init__ | ||
return [] | ||
|
||
if isinstance(self._style, str) and self._style == ",": | ||
# TODO: should we check that there are no empty fields? | ||
# If yes we should do this in __init__ where we validate other styles? | ||
# Do we drop empty fields? | ||
# etc | ||
return [field.strip() for field in self._fmt.split(",") if field.strip()] | ||
Comment on lines
+285
to
+290
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we check that there are no empty fields? |
||
|
||
if isinstance(self._style, logging.StringTemplateStyle): | ||
formatter_style_pattern = STYLE_STRING_TEMPLATE_REGEX | ||
|
||
|
@@ -285,10 +303,7 @@ def parse(self) -> List[str]: | |
else: | ||
raise ValueError(f"Style {self._style!r} is not supported") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs updating. Probably need to find a different representation since |
||
|
||
if self._fmt: | ||
return formatter_style_pattern.findall(self._fmt) | ||
|
||
return [] | ||
return formatter_style_pattern.findall(self._fmt) | ||
|
||
def serialize_log_record(self, log_data: LogData) -> str: | ||
"""Returns the final representation of the data to be logged | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it matter that we do this before checking if the style is valid?
We already (mostly) check for valid style names in
__init__