feat: Принты заменены на библиотеку logging

This commit is contained in:
AURUMVORXX
2025-08-25 18:57:00 +05:00
parent 5666037452
commit 3adc8ab416

View File

@@ -1,4 +1,5 @@
import json import json
import logging
from fastapi import WebSocket, FastAPI, Depends, HTTPException, WebSocketDisconnect, WebSocketException from fastapi import WebSocket, FastAPI, Depends, HTTPException, WebSocketDisconnect, WebSocketException
from fastapi.security import HTTPBasic, HTTPBasicCredentials from fastapi.security import HTTPBasic, HTTPBasicCredentials
from uuid import uuid4 from uuid import uuid4
@@ -12,6 +13,9 @@ class Server:
self._server_password = server_password self._server_password = server_password
self._client_password = client_password self._client_password = client_password
self._logger = logging.getLogger(__name__)
self._logger.addHandler(logging.NullHandler())
self._server_connection: WebSocket | None = None self._server_connection: WebSocket | None = None
self._register_routes(app) self._register_routes(app)
@@ -73,20 +77,20 @@ class Server:
await websocket.accept() await websocket.accept()
self._server_connection = websocket self._server_connection = websocket
self._logger.info('PyG2O сервер подключился')
#TODO: Заменить принты на логирование
try: try:
while True: while True:
try: try:
data = await websocket.receive_text() data = await websocket.receive_text()
message_data = json.loads(data) message_data = json.loads(data)
print('Server message:', message_data) self._logger.info(f'Сообщение сервера: {message_data}')
except json.JSONDecodeError as e: except json.JSONDecodeError as e:
print('JSON Decode exception:', e) self._logger.info(f'Ошибка декодирования JSON: {e}')
except WebSocketDisconnect: except WebSocketDisconnect:
print('Server socket disconnected') self._logger.info('PyG2O сервер отключился')
except WebSocketException as e: except WebSocketException as e:
print('Server socket exception:', e) self._logger.info(f'Ошибка подключения PyG2O сервера: {e}')
async def _process_server_message(self, message: dict): async def _process_server_message(self, message: dict):
match message: match message: