Skip to content

Commit 702bf5d

Browse files
authored
refactor: log WS messages as JSON data instead of a Python dict (#58)
1 parent d297c81 commit 702bf5d

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ _Changes in the next release_
1515
### Changed
1616
- Improved WS msg processing with dedicated consumer, producer and router tasks with asyncio queues ([#47](https://github.com/unfoldedcircle/integration-python-library/pull/47)).
1717
- Sanitize log messages to prevent sensitive information exposure ([#56](https://github.com/unfoldedcircle/integration-python-library/pull/56)).
18+
- Log WebSocket messages as JSON data instead of a Python dict.
1819
- Updated GitHub actions and test dependencies.
1920

2021
---

ucapi/api.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,10 @@ async def init(
147147
self, driver_path: str, setup_handler: uc.SetupHandler | None = None
148148
):
149149
"""
150-
Load driver configuration and start integration-API WebSocket server.
150+
Load driver configuration and start the integration-API WebSocket server.
151151
152-
:param driver_path: path to configuration file
152+
:param driver_path: path to the configuration file. If it is not an absolute
153+
path, the current working directory is used.
153154
:param setup_handler: optional driver setup handler if the driver metadata
154155
contains a setup_data_schema object
155156
"""
@@ -389,7 +390,9 @@ async def _enqueue_ws_payload(self, websocket, payload: dict[str, Any]) -> None:
389390

390391
if _LOG.isEnabledFor(logging.DEBUG):
391392
_LOG.debug(
392-
"[%s] <-: %s", websocket.remote_address, sanitize_json_message(payload)
393+
"[%s] <-: %s",
394+
websocket.remote_address,
395+
json.dumps(sanitize_json_message(payload)),
393396
)
394397

395398
match payload.get("kind"):
@@ -515,7 +518,9 @@ async def _send_ws_event(
515518
async def _process_ws_message(self, websocket, data: dict[str, Any]) -> None:
516519
if _LOG.isEnabledFor(logging.DEBUG):
517520
_LOG.debug(
518-
"[%s] ->: %s", websocket.remote_address, sanitize_json_message(data)
521+
"[%s] ->: %s",
522+
websocket.remote_address,
523+
json.dumps(sanitize_json_message(data)),
519524
)
520525

521526
kind = data["kind"]

0 commit comments

Comments
 (0)