diff --git a/events/sse.py b/events/sse.py index 960a1cd..31df9ed 100644 --- a/events/sse.py +++ b/events/sse.py @@ -8,6 +8,8 @@ from flask import Response from events.types.event import Event +logger = logging.getLogger(__name__) + # Maps user_id → dict of {connection_id: queue} user_queues: Dict[str, Dict[str, queue.Queue]] = {} logging.basicConfig(level=logging.INFO) @@ -33,6 +35,8 @@ def send_to_user(user_id: str, data: Dict[str, Any]): # Send to all connections for this user for connection_id, q in user_queues[user_id].items(): try: + logger.info(f"Sending message to {connection_id}") + q.put(message) q.put(message, block=False) except queue.Full: # Skip if queue is full (connection might be dead) diff --git a/main.py b/main.py index 12761a6..ebf961e 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,5 @@ +import logging + from flask import Flask, request from flask_cors import CORS @@ -9,6 +11,13 @@ from events.broadcaster import Broadcaster from events.sse import sse_response_for_user, send_to_user from db.default import initializeImages +# Configure logging once at application startup +logging.basicConfig( + level=logging.INFO, + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', + datefmt='%Y-%m-%d %H:%M:%S' +) + app = Flask(__name__) #CORS(app, resources={r"/api/*": {"origins": ["http://localhost:3000", "http://localhost:5173"]}}) app.register_blueprint(child_api)