Skip to content

Commit

Permalink
Don't stringify stringify_fields contint if
Browse files Browse the repository at this point in the history
  • Loading branch information
devRoemer committed May 12, 2023
1 parent 852c687 commit 369975a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions sag_py_logging/console_extra_field_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, name: str = "") -> None:
"tags",
"@metadata",
"color_message",
"stringified_extra",
}

def filter(self, record: logging.LogRecord) -> bool:
Expand Down
25 changes: 25 additions & 0 deletions tests/test_console_extra_field_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,28 @@ def test_with_extra_fields(log_record: LogRecord) -> None:
'my_extra_not_serializable_object={"testtext": "test"}, '
"my_extra_object_without_dict=ClassWithoutDict(x=123, y=456)"
)


def test_with_extra_fields_when_called_twice(log_record: LogRecord) -> None:
# Arrange
filter_ = ConsoleExtraFieldFilter()
log_record.my_extra_string = "test"
log_record.my_extra_int = 1
log_record.my_extra_bool = True
log_record.my_extra_dict_object = {"keyOne": "valueOne", "keyTwo": 2}
log_record.my_extra_not_serializable_object = NotSerializableClass("test")
log_record.my_extra_object_without_dict = ClassWithoutDict(x=123, y=456)

# Act
filter_.filter(log_record)
filter_.filter(log_record)

# Assert
assert (
cast(ExtraFieldsLogRecord, log_record).stringified_extra == 'my_extra_string="test", '
"my_extra_int=1, "
"my_extra_bool=true, "
'my_extra_dict_object={"keyOne": "valueOne", "keyTwo": 2}, '
'my_extra_not_serializable_object={"testtext": "test"}, '
"my_extra_object_without_dict=ClassWithoutDict(x=123, y=456)"
)

0 comments on commit 369975a

Please sign in to comment.