|
import queue |
|
import logging |
|
import sys |
|
from datetime import datetime |
|
|
|
|
|
notification_queue = queue.Queue() |
|
|
|
|
|
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) |
|
""" |
|
|
|
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
|
|
|
|
|
print(f"[{timestamp}] {level}: {message}") |
|
|
|
|
|
type_map = { |
|
"INFO": "info", |
|
"WARNING": "warning", |
|
"ERROR": "error", |
|
"SUCCESS": "success" |
|
} |
|
|
|
|
|
notification_queue.put({ |
|
"type": type_map.get(level, "info"), |
|
"message": f"{message}", |
|
"timestamp": timestamp |
|
}) |
|
|