import queue import logging import sys from datetime import datetime # Create notification queue notification_queue = queue.Queue() # Setup logging logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[logging.StreamHandler(sys.stdout)] ) logger = logging.getLogger(__name__) def log_print(message, level="INFO"): """ Log a message both to the console and send it to the frontend via notification queue Args: message (str): The message to log level (str): The log level (INFO, WARNING, ERROR, SUCCESS) """ # Get timestamp timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") # Log to console print(f"[{timestamp}] {level}: {message}") # Map log level to notification type type_map = { "INFO": "info", "WARNING": "warning", "ERROR": "error", "SUCCESS": "success" } # Send to frontend via notification queue notification_queue.put({ "type": type_map.get(level, "info"), "message": f"{message}", "timestamp": timestamp })