File size: 1,135 Bytes
fce85c0 c083a98 fce85c0 c083a98 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
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
})
|