Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ def _convert_any_value_to_string(value: Any) -> str:
return str(value)
if isinstance(value, (list, tuple)):
return json.dumps(value)
logging.warning(
"Unknown value %s found, cannot convert to string.", type(value)
)
return ""


Expand Down Expand Up @@ -158,7 +155,7 @@ def _set_payload_in_log_entry(log_entry: LogEntry, body: AnyValue):
log_entry.json_payload = struct
else:
log_entry.text_payload = base64.b64encode(body).decode()
else:
elif body is not None:
log_entry.text_payload = _convert_any_value_to_string(body)


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"entries": [
{
"logName": "projects/fakeproject/logs/test",
"resource": {
"labels": {
"location": "global",
"namespace": "",
"node_id": ""
},
"type": "generic_node"
},
"timestamp": "2025-01-15T21:25:10.997977393Z"
}
],
"partialSuccess": true
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,16 @@ def test_convert_non_json_dict_bytes(

@pytest.mark.parametrize(
"body",
[pytest.param("A text body", id="str"), pytest.param(True, id="bool")],
[
pytest.param("A text body", id="str"),
pytest.param(True, id="bool"),
pytest.param(None, id="None"),
],
)
def test_convert_various_types_of_bodies(
cloudloggingfake: CloudLoggingFake,
snapshot_writelogentrycalls: List[WriteLogEntriesCall],
body: Union[str, bool],
body: Union[str, bool, None],
) -> None:
log_data = [
LogData(
Expand Down