import logging import pymongo from datetime import datetime from dotenv import load_dotenv import os load_dotenv() # MongoDB setup client = pymongo.MongoClient(os.getenv("MONGO_URI")) db = client["Capstone"] log_collection = db["logs"] class MongoHandler(logging.Handler): def emit(self, record): log = { "level": record.levelname, "message": record.getMessage(), "timestamp": datetime.now() } log_collection.insert_one(log) # Configure logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger("ProjectLogger") logger.addHandler(MongoHandler())