From ebc5e1306a0d23f23ba2fc80288537d21dbe8dc1 Mon Sep 17 00:00:00 2001 From: BluemediaGER Date: Sat, 20 Apr 2024 17:14:45 +0200 Subject: [PATCH] Add ocpp message logging --- app/util/websocket_wrapper.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/util/websocket_wrapper.py b/app/util/websocket_wrapper.py index ec6a029..c6a95b1 100644 --- a/app/util/websocket_wrapper.py +++ b/app/util/websocket_wrapper.py @@ -1,6 +1,9 @@ +import logging from fastapi import WebSocket, WebSocketDisconnect from websockets import ConnectionClosed +logger = logging.getLogger("gunicorn.access") + # Wrapper to transform a FastAPI websocket to a standard websocket class WebSocketWrapper(): def __init__(self, websocket: WebSocket): @@ -8,11 +11,14 @@ class WebSocketWrapper(): async def recv(self) -> str: try: + text = await self._websocket.receive_text() + logger.info("Message received: {}", text) return await self._websocket.receive_text() except WebSocketDisconnect as e: raise ConnectionClosed(e.code, 'WebSocketWrapper') async def send(self, msg: str) -> None: + logger.info("Message sent: {}", msg) await self._websocket.send_text(msg) async def close(self, code: int, reason: str) -> None: